Maybe a problem? undetected name clash makes static method unaccessible through outside static reference
| From: | Martin Alterisio | Date: | Thu, 20 Dec 2007 23:36:08 +0000 |
| Subject: | Maybe a problem? undetected name clash makes static method unaccessible through outside static reference | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-34188@lists.php.net to get a copy of this message | ||
Consider the following code:
foo.php:
<?php
class test {
public static function foo() { echo "I'm foo in class test\n"; }
public static function foo2() { self::foo(); }
}
?>
foo2.php:
<?php
namespace test;
function foo() { echo "I'm foo in namespace test\n"; }
?>
test.php:
<?php
include 'foo.php';
include 'foo2.php';
test::foo(); // I'm foo in namespace test
use test::foo as dummy;
test::foo(); // I'm foo in namespace test
test::foo2(); // I'm foo in class test
$test = 'test';
$test::foo(); // I'm foo in class test
call_user_func(array('test', 'foo')); // I'm foo in class test
?>
Please review the following observations:
There's a name clash that goes undetected: test::foo refers to both a
namespaced function and a static method.
Once the clash occur there's no way to refer to the static method through a
static reference, except when within the class scope where you can refer to
the method through self::
The static method remains partially hidden by the namespaced function.
Best Regards,
Martin Alterisio