Jump to content

Variable class names and static vars


flaab

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/84486-variable-class-names-and-static-vars/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.