my life

day to day

Archive for July 14th, 2006

PHP5 OOP must haves

Friday, July 14th, 2006

We’re always taught when learning OOP to be a strict as possible when declaring methods/members as public, private and protected. For some reason though, when programming PHP we’re in this mode that since it’s a scripting language “let’s not adhere to better practice”. Well, atleast I kind of fall for this and going by all of the other peoples code that I’ve read it’s not too uncommon. The project I’m working on has reaffirmed that there is no excuse for sloppy programming.

When writing OO PHP5, always start by making all properties private or protected. Declare the overloading/accessor methods for __set, __get, and __unset. Throw as many exceptions as possible and things will debug themselves with little or not effort on the programmer.

Asside from protecting your privates, this method aids in profiling your code too. Since by moving your assignments and gets into a function call, they can now be counted by a PHP profiler such as apd.

 

add to del.icio.us    add to technorati favs   email this