note 80310 modified in language.oop5.overloading by levim
| From: | levim@php.net | Date: | Mon, 16 Nov 2015 02:02:25 +0000 |
| Subject: | note 80310 modified in language.oop5.overloading by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-204158@lists.php.net to get a copy of this message | ||
It should be noted that __call will trigger only for method calls on an instantiated object, and
cannot be used to 'overload' static methods. For example:
<?php
class TestClass {
function __call($method, $args) {
echo "Method {$method} called with args: " . print_r($args, TRUE);
}
}
// this will succeed
$obj = new TestClass();
$obj->method_doesnt_exist();
// this will not
TestClass::method_doesnt_exist();
?>
It would be useful if the PHP devs would include this in a future release, but in the meantime, just
be aware of that pitfall.
--was--
it should be noted that __call will trigger only for method calls on an instantiated object, and
cannot be used to 'overload' static methods. for example:
<?php
class TestClass {
function __call($method, $args) {
echo "Method {$method} called with args: " . print_r($args, TRUE);
}
}
// this will succeed
$obj = new TestClass();
$obj->method_doesnt_exist();
// this will not
TestClass::method_doesnt_exist();
?>
It would be useful if the PHP devs would include this in a future release, but in the meantime, just
be aware of that pitfall.
http://php.net/manual/en/language.oop5.overloading.php