Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // When we call any undefined method of class then it will look for __call method of that class
- // If __call is also not defined then it will show error
- // So I am showing how we can implement method overloading with in PHP with the use of Magic Methods
- class a {
- public function __call($name, $args) {
- echo "I am in ". $name. ' with '. count($args). ' Arguments';
- echo "<br>";
- }
- }
- // Chota have jo a class ma koi j method nathi. just __call j 6.
- // 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.
- // Creating object
- $a = new a();
- $a->undefined();
- $a->undefined('1');
- $a->undefined('1','2');
- $a->undefined('1','2','3');
- $a->undefined('1','2','3', '4');
- // Output:
- /*
- * I am in undefined with 0 Arguments
- * I am in undefined with 1 Arguments
- * I am in undefined with 2 Arguments
- * I am in undefined with 3 Arguments
- * I am in undefined with 4 Arguments
- *
- * */
- // 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.
- // Kahbar Padi chota?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement