Advertisement
Guest User

Method Overloading

a guest
Mar 27th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. // When we call any undefined method of class then it will look for __call method of that class
  2. // If __call is also not defined then it will show error
  3.  
  4. // So I am showing how we can implement method overloading with in PHP with the use of Magic Methods
  5.  
  6. class a {
  7.    
  8.     public function __call($name, $args) {
  9.        
  10.         echo "I am in ". $name. ' with '. count($args). ' Arguments';
  11.         echo "<br>";
  12.        
  13.     }
  14.    
  15. }
  16.  
  17. // Chota have jo a class ma koi j method nathi. just __call j 6.
  18. // have jo hu koi pan method call kari to e __call ma jase. Kem k e method defined j nathi and __call ma catch thase.
  19.  
  20. // Creating object
  21. $a = new a();
  22.  
  23. $a->undefined();
  24. $a->undefined('1');
  25. $a->undefined('1','2');
  26. $a->undefined('1','2','3');
  27. $a->undefined('1','2','3', '4');
  28.  
  29.  
  30. // Output:
  31. /*
  32.  * I am in undefined with 0 Arguments
  33.  * I am in undefined with 1 Arguments
  34.  * I am in undefined with 2 Arguments
  35.  * I am in undefined with 3 Arguments
  36.  * I am in undefined with 4 Arguments
  37.  *
  38.  * */
  39.  
  40. // So aapde ek j method name call kari but arguments diff hata. Actually evi koi method hati j nai but magic methos ma e catch thai ne tya thi process thai.
  41.  
  42. // Kahbar Padi chota?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement