Re: About the magic function __call
| From: | Paulo Sousa | Date: | Wed, 27 Aug 2008 20:29:46 +0000 |
| Subject: | Re: About the magic function __call | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278833@lists.php.net to get a copy of this message | ||
My information was incomplete: I'm running php 5.1.2 (a requirement from the
customer).
I found this http://bugs.php.net/bug.php?id=42937
I "coded" this without testing, using only the idea. Thanks!
Thanks for the help Nathan!
2008/8/27 Nathan Nobbe <quickshiftin@gmail.com>
> On Wed, Aug 27, 2008 at 1:49 PM, Nathan Nobbe <quickshiftin@gmail.com>wrote:
>
>> On Wed, Aug 27, 2008 at 1:35 PM, Paulo Sousa <paulo.sousa.filho@gmail.com
>> > wrote:
>> ...
>>
>
> this *should* work,
>
> here is a test, tests/classes/__call_005.phpt, you can take the part
> beneath the --FILE-- section and see if it blows up on your system or not.
> right now, im getting errors on a php5.2.5 system, and its working as
> expected on a php5.2.6 system.
>
> --TEST--
> When __call() is invoked via ::, ensure private implementation of __call()
> in superclass is accessed without error.
> --FILE--
> <?php
> class A {
> private function __call($strMethod, $arrArgs) {
> echo "In " . __METHOD__ . "($strMethod, array(" .
> implode(',',$arrArgs) . "))\n";
> var_dump($this);
> }
> }
>
> class B extends A {
> function test() {
> A::test1(1,'a');
> B::test2(1,'a');
> self::test3(1,'a');
> parent::test4(1,'a');
> }
> }
>
> $b = new B();
> $b->test();
> ?>
> --EXPECTF--
> In A::__call(test1, array(1,a))
> object(B)#1 (0) {
> }
> In A::__call(test2, array(1,a))
> object(B)#1 (0) {
> }
> In A::__call(test3, array(1,a))
> object(B)#1 (0) {
> }
> In A::__call(test4, array(1,a))
> object(B)#1 (0) {
> }
>
> also, i found in the code you posted, you are missing a 'function' in front
> of doWhatever (cause a parse error, which is why i mention it); w/ the
> following modification to your code, its running fine on a php 5.2.6 system,
> and choking on 5.2.5;
>
> function __call($function, $args){
> var_dump($function);
> var_dump($args);
> $this->doWhatever();
> }
>
> private function doWhatever() {
> }
>
> nathan@devel ~/unpack/php-5.2.6RC3/tests/classes $ php testOtherStuff.php
> string(5) "drive"
> array(1) {
> [0]=>
> string(7) "testing"
> }
>
> -nathan
>
> (sorry for the long-winded post)
>