The conventions to be followed for OOP in PHP


Hi guys,

I always give preference to the conventions over configurations. If somebody wants to be a professional programmer then must follow the conventions.

Here are some conventions i came up with based on PEAR Coding Standards which are good.

1. ClassName – Emailer, Logger, ErrorHandler, PEAR(this is a package name, that is why, it is in CAPS)

2. Public Methods – log, logError, PEAR_init (to avoid method name collisions between packages)

3. Protected Methods – _log, _logError, _PEAR_initMe

4. Private Methods – __log, __logError, __PEAR_initMe

5. Constant/Static Variables – MY_FIRST_CONSTANT, PEAR_MY_FIRST_CONSTANT(to var name collisions between packages)

6. Global Variables – $_MY_FIRST_GLOBAL, $_PEAR_MY_FIRST_GLOBAL(to avoid var name collisions between packages)

I hope this will help to improve us. And this way, we can remember conventions easily, that is why i did not give the full description.

Advertisement