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.

Advertisements

One thought on “The conventions to be followed for OOP in PHP

  1. that’s something good, can i expect some tip n’ trix about effective use of programming features, like proper use of global variables, then use of various loops, and your preferred way of writing a program

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s