Object oriented programming first appeared in PHP 4. The implementation was fairly minimal until PHP 5. Therefore, I will split the discussion on object oriented programming into two sections: one on PHP 4 and the other on PHP 5.
Object types (classes) can be defined with the class keyword:
This example demonstrates a very language features. The name of the class or object type, Gene_Info, follows
the class keyword. Inheritance can be used with the extends keyword
but I will not demonstrate that.
The Gene_Info class declares three member variables id, symbol, and name.
The constructor is a method (function) with the same name as the class. It is invoked when a new
object instance is created with the new keyword. Code within the class definition can use the
$this psuedo variable to access member variables (not the absence of the $ for member variables).
The program output is
Objects can be serialized with the predefined function serialize(). This is useful for
storing them in a
user session. They can be unserialized with the predefined unserialize() function.
There are no user comments.
Please send ideas and opinions by email at alexamies@gmail.com.