Late static binding - syntax error
Posted: Fri Aug 22, 2014 3:05 pm
Hello Everyone!
I have the following simple code:
The code returns AB is OK, however I would like to catch get_called_class() in a variable and instantiate the classes:
var $class_name = get_called_class();
$object = new $class_name;
I am using Dreamweaver CS6 and I get an syntax error on this: var $class_name = get_called_class();
What is more stranger that get_called_class() does not show up in the code completion but I checked that the function exist:
function_exists(get_called_class); returns true;
Why i cannot do this?: var $class_name = get_called_class(); // returns a string as i know
If I could, my code would have been simplified a lot.
Somebody could help on this?
I have the following simple code:
Code: Select all
<?php
class A {
public static function name()
{
echo get_called_class();
}
}
class B extends A {
}
A::name();
B::name();
?>
var $class_name = get_called_class();
$object = new $class_name;
I am using Dreamweaver CS6 and I get an syntax error on this: var $class_name = get_called_class();
What is more stranger that get_called_class() does not show up in the code completion but I checked that the function exist:
function_exists(get_called_class); returns true;
Why i cannot do this?: var $class_name = get_called_class(); // returns a string as i know
If I could, my code would have been simplified a lot.
Somebody could help on this?