April 23, 2005 | Web Design & Development
The next logical step in my education of PHP is to learn PHP5’s implementation of OOP. I started that this morning and wrote myself a short, useless script using a couple of the new features in PHP5.
I learned how to use static variables and constructors. Not bad for my first hour. :: cue child’s voice :: I made this:
static $counter = 0;
// constructor runs at function open
$this->id = self::$counter;
Class myObj extends MyCounter
return $this->id ."n";
$one = new myObj();
$two = new myObj();
It returns a value of 1 for $one and a value of 2 for $two.
Pretty much all it does is inherit and increment the myCounter Class each time the myObj class is instantiated, but still its pretty cool. I haven’t even done anything constructive with OOP and I’m already excited about it.
Now onto Polymorphism.