Edit report at https://bugs.php.net/bug.php?id=55839&edit=1

 ID:                 55839
 Updated by:         johan...@php.net
 Reported by:        chris at mcfadyen dot ca
 Summary:            Static accessors through variables only work on
                     simple variables
 Status:             Bogus
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Windows
 PHP Version:        5.3SVN-2011-10-03 (SVN)
 Block user comment: N
 Private report:     N

 New Comment:

Here is the reduced case:

class ClassOne {
    public $referrer = 'ClassTwo';
}

$b = new ClassOne();
echo ${$b->referrer};

${$b->referrer}; is $classTwo. That variable does not exist.


Previous Comments:
------------------------------------------------------------------------
[2011-10-03 20:17:58] chris at mcfadyen dot ca

It's not supposed to reference $b, it's supposed to reference the class B

$b::foo() is de-referenced as B::foo()
Why would ${$a->referrer}::foo() not de-reference to B::foo() as well?


To make it more obvious so that you can't misinterpret it:

class ClassOne {
    public $referrer = 'ClassTwo';
}

class ClassTwo {
    public static function foo() {
        echo "Foo";
    }
}

$a = 'ClassTwo';
$b = new ClassOne();

$a::foo();

${$b->referrer}::foo();

$c = $b->referrer;
$c::foo();

Which gives the notice "Undefined variable: ClassTwo"

------------------------------------------------------------------------
[2011-10-03 18:53:33] johan...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Variable names are case-sensitive. $B is not the same as $b.

${$a->referrer}::foo(); in your case is the same as $B::foo()m not $b::foo();

------------------------------------------------------------------------
[2011-10-03 18:47:14] chris at mcfadyen dot ca

Description:
------------
Using a static operator ( :: ) works for simple variables ( $foo::function() ), 
but results in an undefined variable warning for the class name at run-time 
when 
using a class property ( ${$bar->foo}::function() ).  Obviously, a direct 
access 
attempt ( $bar->foo::function() ) fails with a parse error.

---
>From manual page: http://www.php.net/language.oop5.static
---


Test script:
---------------
class A {
    public $referrer = 'B';
}

class B {
    public static function foo() {
        echo "Foo";
    }
}

$b = 'B';
$a = new A();

$b::foo();

${$a->referrer}::foo();

$c = $a->referrer;
$c::foo();

Expected result:
----------------
I would expect to see

Foo
Foo
Foo

Actual result:
--------------
This is the result:

Foo
Notice (8): Undefined variable: B
Foo


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=55839&edit=1

Reply via email to