Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

Ox41464b
Wednesday, August 9th, 2006 at 9:09:27am UTC 

  1. <?php
  2. class Dog
  3. {
  4.         public function Bark() {}
  5. }
  6. class Monkey
  7. {
  8.         public function Climb() {}
  9. }
  10. class Fish
  11. {
  12.         public function Swim() {}
  13. }
  14.  
  15.  
  16. class ObjectMerger
  17. {
  18.         public $ObjectContainer=array();
  19.         public function __call($method, $argv)
  20.         {
  21.                 foreach ($this->ObjectContainer as $Object)
  22.                 {
  23.                         if (in_array($method, get_class_methods(get_class($Object))))
  24.                         {
  25.                                 echo "Calling ".$method."\n";
  26.                                 return true;
  27.                         }
  28.                 }
  29.  
  30.                 echo "Unknown method $method\n";
  31.                 return false;
  32.         }
  33.         public function addObject($Object)
  34.         {
  35.                 $this->ObjectContainer[]=$Object;
  36.         }
  37. }
  38.  
  39.  
  40.  
  41. $newSpecies=new ObjectMerger;
  42. $newSpecies->addObject(new Dog);
  43. $newSpecies->Bark();
  44.  
  45. $newSpecies->addObject(new Monkey);
  46. $newSpecies->Climb();
  47.  
  48. $newSpecies->addObject(new Fish);
  49. $newSpecies->Swim();
  50.  
  51. $newSpecies->UnknownCall();
  52. /*
  53. Output:
  54. C:\>php -f ObjectMerger.php
  55. Calling Bark
  56. Calling Climb
  57. Calling Swim
  58. Unknown method UnknownCall
  59. */
  60. ?>

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right