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 6 • OBJECT-ORIENTED <strong>PHP</strong>www.it-ebooks.info■ Note <strong>PHP</strong> 4 also offered class constructors, but it used a different, more cumbersome syntax than the one usedin version 5. Version 4 constructors were simply class methods of the same name as the class they represented.Such a convention made it tedious to rename a class. The new constructor-naming convention resolves theseissues. For reasons of compatibility, however, if a class is found to not contain a constructor satisfying the newnaming convention, that class will then be searched for a method bearing the same name as the class; if located,this method is considered the constructor.<strong>PHP</strong> recognizes constructors by the name __construct (a double underscore precedes theconstructor keyword). The general syntax for constructor declaration follows:function __construct([argument1, argument2, ..., argumentN]){// Class initialization code}As an example, suppose you want to immediately populate certain book properties withinformation specific to a supplied ISBN. For example, you might want to know the title and author of abook, in addition to how many copies the library owns and how many are presently available for loan.The code might look like this:

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

Saved successfully!

Ooh no, something went wrong!