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.infoInvoking MethodsMethods are invoked in almost exactly the same fashion as functions. Continuing with the previousexample, the calculateSalary() method would be invoked like so:$employee = new Employee("Janie");$salary = $employee->calculateSalary();Method Scopes<strong>PHP</strong> supports six method scopes: public, private, protected, abstract, final, and static. The first fivescopes are introduced in this section. The sixth, static, is introduced in the later section “Static ClassMembers.”PublicPublic methods can be accessed from anywhere at any time. You declare a public method by prefacing itwith the keyword public or by forgoing any prefacing whatsoever. The following example demonstratesboth declaration practices, in addition to demonstrating how public methods can be called from outsidethe class:Visitors::greetVisitor();$visitor = new Visitors();$visitor->sayGoodbye();The following is the result:HelloGoodbye146

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

Saved successfully!

Ooh no, something went wrong!