Getting value of static vars dinamically
Posted: Fri Jan 16, 2009 9:05 am
EVERAH | PLEASE USE PHP OR CODE BBCODE TAGS WHEN POSTING CODE IN THE FORUMS.
Hello,
any one could help me ?
I'm trying to get the value of a static var by passing its name in a method (getString($varname)), but for the moment I've not found the correct way, it only returns the text "Texts::$first" but not its value.
Anyone know what the problem is ?
Thanks !
Hello,
any one could help me ?
I'm trying to get the value of a static var by passing its name in a method (getString($varname)), but for the moment I've not found the correct way, it only returns the text "Texts::$first" but not its value.
Anyone know what the problem is ?
Code: Select all
class Texts {
public static $first = "hello";
}
class One {
public static function getString($varname) {
$x = "Texts::$$varname";
return (string) $x;
}
}
@echo One::getString("first");
// The output should be "hello", but it does not work and returns "Texts::$first"