View Single Post
Old 08-28-08, 02:01 PM   #29
Ngemu Mod
Join Date: Jul 2003
Location: Fresno, CA
Posts: 1,886
Default Re: Learn PHP/MySQL Feedback Thread

Your object definitions don't have a class constructor. Most OOP languages use constructors to initialize object variables. PHP is far more lenient in this regard and allows variables to be created on the whim without initialization. It does throw a bunch of warnings though.

A discussion about classes and objects also needs to touch on passing variables by reference and by value. PHP by default, makes all variables passed into functions by reference. There is a value in the php.ini to change it to pass by value. You can then pass by reference only when you explicitly do so. Ie.

function passbyreference(&$str, &$obj, Array &$arr){

  // do something
All the arguments in that function will be passed by reference. According to the PHP.ini file, the default behavior of passing by reference will be deprecated in future versions of PHP(PHP6). It's wise to make your functions explicitly pass by reference if that's how you designed them to function. This default behavior caused me some headaches when my object variables were changing values when I didn't want them to after being passed into a function.
[i7 2600k @4.4ghertz][2x4 GB DDR3 1600][EVGA GTX570 1.280GB SC][EVGA GTX460 physx][Asrock Extreme7 Gen3 Z68][2xSeagate 160 Gb SATA HD raid0][Seagate 250 GB SATA2 HD][Sony Bravia 40' 1080p LCD HDTV][NEC 3520a DVD+-DLw][Windows 7 Ultimate x64][Rosewill 1000w]
fivefeet8 is offline   Reply With Quote