flaab Posted January 4, 2008 Share Posted January 4, 2008 Hi :-) I've been trying to do this for a long time...how can I make this work? I always get an error :-) <?php class Foo { public static $my_static = 'foo'; } $classname = 'Foo'; print $classname::$my_static ; ?> It's an officla php example from the official website...but it does not work :-S Quote Link to comment https://forums.phpfreaks.com/topic/84486-variable-class-names-and-static-vars/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 4, 2008 Share Posted January 4, 2008 Posting the error message and telling us what version of php you are using would help. Quote Link to comment https://forums.phpfreaks.com/topic/84486-variable-class-names-and-static-vars/#findComment-430443 Share on other sites More sharing options...
flaab Posted January 4, 2008 Author Share Posted January 4, 2008 Yeah :-) Php version is... arturo@firecracker ~ $ php --version PHP 5.2.4-2 with Suhosin-Patch 0.9.6.2 (cli) (built: Oct 24 2007 20:08:19) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies And PHP error triggered is... Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /var/www/static.php on line 10 And the code is still... <?php class Foo { const constant = 'Cadena de mierda'; } $classname = 'Foo'; print $classname::constant; ?> thx Quote Link to comment https://forums.phpfreaks.com/topic/84486-variable-class-names-and-static-vars/#findComment-430454 Share on other sites More sharing options...
PFMaBiSmAd Posted January 4, 2008 Share Posted January 4, 2008 Your php version is not high enough to support using a variable to reference the class name. Form the php manual - As of PHP 5.3.0, it's possible to reference the class using a variable. Quote Link to comment https://forums.phpfreaks.com/topic/84486-variable-class-names-and-static-vars/#findComment-430467 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.