Something like overloading in PHP?

Php interface Turnable { public function turn(); } class Screwdriver implements Turnable { public function turn() { print "to turning sir! \n"; } } class SteeringWheel implements Turnable { public function turn() { print "to everything, turn, turn turn! \n"; } } function turn(Turnable $object) { $object->turn(); } $driver = new Screwdriver(); turn($driver); $wheel = new SteeringWheel(); turn($wheel); $obj = new Object(); // any object that does not implement Turnable turn($object); // ERROR!

PHP does permit you to use a type hint for the parameter, and the type hint can be an interface name instead of a class name. So you can be sure that if the $object implements the Turnable interface, then it must have the turn() method. Each class that implements Turnable can do its own thing to accomplish turning.

I read davethegr8's solution but it seems one could do the same thing with stronger typing: turn(); } $driver = new Screwdriver(); turn($driver); $wheel = new SteeringWheel(); turn($wheel); $obj = new Object(); // any object that does not implement Turnable turn($object); // ERROR! PHP does permit you to use a type hint for the parameter, and the type hint can be an interface name instead of a class name. So you can be sure that if the $object implements the Turnable interface, then it must have the turn() method.

Each class that implements Turnable can do its own thing to accomplish turning.

Very nice that. My immediate thought was interface inheritance, but I left the PHP world before learning OOP. – cjk Jan 25 '09 at 19:58 Nice turn of phase sir!

And well put. +1 – meouw Jan 25 '09 at 21:38.

I think this will work... function turn($object) { if(method_exists($object, 'turn'. Ucwords(get_class($object))) { $fname = 'turn'. Ucwords(get_class($object)); return $object->$fname(); } return false; }.

You need to check the PHP Manual for instructions here.

However, when you return the array, PHP treats it just as it should. THat is, you'd have to make an array with the index of "one" in __get in order to see any results. You can also have other indexes in there as well.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions