note 109788 added to language.oop5.late-static-bindings
| From: | Taai | Date: | Tue, 21 Aug 2012 10:36:56 +0000 |
| Subject: | note 109788 added to language.oop5.late-static-bindings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190152@lists.php.net to get a copy of this message | ||
I discovered an interesting thing. The class name string must be accessed directly from
"flat" variable. Late static binding code that get's it's variable from array
that is passed by class instance, throws an syntax error. Bug?
<?php
class A {
public $metadata = array('class' => 'A');
public static function numbers()
{
return 123;
}
}
$instance = new A();
// This throws an error
// Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)
var_dump( $instance->metadata['class']::numbers() );
// Get the class name and store it in "flat" variable and now it's ok
$class_name = $instance->metadata['class'];
var_dump( $class_name::numbers() );
// Other tests -------------------------------------------
$arr = array('class' => 'A');
// This works too.
var_dump( $arr['class']::numbers() );
?>
----
Server IP: 69.147.83.197
Probable Submitter: 89.248.82.8
----
Manual Page -- http://www.php.net/manual/en/language.oop5.late-static-bindings.php
Edit -- https://master.php.net/note/edit/109788
Del: integrated -- https://master.php.net/note/delete/109788/integrated
Del: useless -- https://master.php.net/note/delete/109788/useless
Del: bad code -- https://master.php.net/note/delete/109788/bad+code
Del: spam -- https://master.php.net/note/delete/109788/spam
Del: non-english -- https://master.php.net/note/delete/109788/non-english
Del: in docs -- https://master.php.net/note/delete/109788/in+docs
Del: other reasons-- https://master.php.net/note/delete/109788
Reject -- https://master.php.net/note/reject/109788
Search -- https://master.php.net/manage/user-notes.php