11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 7 • ADVANCED OOP FEATURESwww.it-ebooks.infoAdvanced OOP Features Not Supported by <strong>PHP</strong>If you have experience in other object-oriented languages, you might be scratching your head over whythe previous list of features doesn’t include certain OOP features supported by other programminglanguages. The reason might well be that <strong>PHP</strong> doesn’t support those features. To save you from furtherwonderment, the following list enumerates the advanced OOP features that are not supported by <strong>PHP</strong>and thus are not covered in this chapter:Method overloading: The ability to implement polymorphism through methodoverloading is not supported by <strong>PHP</strong> and probably never will be.Operator overloading: The ability to assign additional meanings to operatorsbased upon the type of data you’re attempting to modify is currently not supportedby <strong>PHP</strong>. Based on discussions found in the <strong>PHP</strong> developer’s mailing list, it isunlikely that this feature will ever be implemented.Multiple inheritance: <strong>PHP</strong> does not support multiple inheritance. Implementationof multiple interfaces is supported, however.Only time will tell whether any or all of these features will be supported in future versions of <strong>PHP</strong>.Object CloningOne of the biggest drawbacks to <strong>PHP</strong> 4’s object-oriented capabilities was its treatment of objects as justanother datatype, which impeded the use of many common OOP methodologies, such as designpatterns. Such methodologies depend on the ability to pass objects to other class methods as references,rather than as values. Thankfully, this matter has been resolved with <strong>PHP</strong> 5, and now all objects aretreated by default as references. However, because all objects are treated as references rather than asvalues, it is now more difficult to copy an object. If you try to copy a referenced object, it will simplypoint back to the addressing location of the original object. To remedy the problems with copying, <strong>PHP</strong>offers an explicit means for cloning an object.Cloning ExampleYou 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 namedCorporate_Drone, which contains two properties (employeeid and tiecolor) and corresponding gettersand setters for these properties. The example code instantiates a Corporate_Drone object and uses it asthe basis for demonstrating the effects of a clone operation.Listing 7-1. Cloning an Object with the clone Keyword

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!