From 7bd3028ed969f681a13bbd55f2782ca4fd51cc27 Mon Sep 17 00:00:00 2001 From: Daniel Convissor Date: Sat, 1 Mar 2008 02:59:26 +0000 Subject: [PATCH] Add __callStatic() to oop5 Overloading page and clarify __call() example. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@254010 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/oop5/overloading.xml | 96 +++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 28 deletions(-) diff --git a/language/oop5/overloading.xml b/language/oop5/overloading.xml index bb967ee9d7..29e89052c7 100644 --- a/language/oop5/overloading.xml +++ b/language/oop5/overloading.xml @@ -1,5 +1,5 @@ - + Overloading @@ -8,8 +8,6 @@ __call, __get and __set methods. These methods will only be triggered when your object or inherited object doesn't contain the public member or method you're trying to access. - All overloading methods must not be defined as - static. All overloading methods must be defined as public. @@ -169,36 +167,43 @@ object(Setter)#1 (2) { stringname arrayarguments + + mixed__callStatic + stringname + arrayarguments + - The magic method __call() allows to capture invocation of non existing - methods. That way __call() can be used to implement user defined method + The magic methods __call() and __callStatic() + allow capturing invocation of non existent methods. + These methods can be used to implement user defined method handling that depends on the name of the actual method being called. This is for instance useful for proxy implementations. The arguments that were passed in the function will be defined as an array in the - $arguments parameter. The value returned from the - __call() method will be returned to the caller of the method. + $arguments parameter. The value returned from these + methods will be returned to the caller of the method. + - overloading with __call example + overloading instantiated methods with __call x; } } $foo = new Caller(); -$a = $foo->test(1, "2", 3.4, true); +$a = $foo->test('a', 'b'); var_dump($a); ?> ]]> @@ -207,26 +212,61 @@ var_dump($a); - int(1) - [1]=> - string(1) "2" - [2]=> - float(3.4) - [3]=> - bool(true) +Instantiated method 'test' called: +array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" } -array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) +array(2) { + [0]=> + int(10) + [1]=> + int(20) } + + + + + overloading instantiated methods with __call + + ]]> + + &example.outputs; + + + string(1) "a" + [1]=> + string(1) "b" +} +array(2) { + [0]=> + int(10) + [1]=> + int(20) +}