Prev | Current Page 262 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


Multiple inheritance: PHP does not support multiple inheritance. Implementation
of multiple interfaces is supported, however.
Only time will tell whether any or all of these features will be supported in future
versions of PHP.
Object Cloning
One of the biggest drawbacks to PHP 4??™s object-oriented capabilities is its treatment
of objects as just another datatype, which impeded the use of many common OOP
methodologies, such as design patterns. Such methodologies depend on the ability to
pass objects to other class methods as references, rather than as values, which is no
longer PHP??™s default practice. Thankfully, this matter has been resolved with PHP 5,
and now all objects are treated by default as references. However, because all objects
are treated as references rather than as values, it is now more difficult to copy an
object. If you try to copy a referenced object, it will simply point back to the addressing
location of the original object. To remedy the problems with copying, PHP offers an
explicit means for cloning an object.
CHAPTER 7 ?–  ADVANCED OOP FEATURES 195
Cloning Example
You clone an object by prefacing it with the clone keyword, like so:
destinationObject = clone targetObject;
Listing 7-1 presents an object-cloning example. This example uses a sample class
named Corporate_Drone, which contains two members (employeeid and tiecolor) and
corresponding getters and setters for these members.


Pages:
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274