Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.