O'Reilly logo

Sams Teach Yourself PHP in 24 Hours, Third Edition by Matt Zandstra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Tools for Building Object Hierarchies

In this section, we delve even deeper into object-oriented design issues. We have already seen how useful the hints are in method arguments introduced with PHP 5. Hints are important because we can be sure that when using them we will be working with an object of a particular type. We encountered this earlier in this hour:

public function update( Item $item ) {
  print "updating.. ";
  print $item->name;
}

The update() method knows that it has an Item object and can go ahead and work with the $name property that it knows will be accessible. So by constraining the type of the argument passed to the method, we ensure the interface of the object.

Abstract classes and interfaces are ways of doing a similar thing. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required