[PHP] Re: Getting static member for a class which name is stored in a variable

2004-11-26 Thread Daniel Schierbeck
Daniel Schierbeck wrote:
public static function getData ()
Ooops, the method shouldn't have been static :)
--
Daniel Schierbeck
Help spread Firefox (www.getfirefox.com): 
http://www.spreadfirefox.com/?q=user/registerr=6584

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Getting static member for a class which name is stored in a variable

2004-11-25 Thread Daniel Schierbeck
Francisco M. Marzoa Alonso wrote:
I've code like follows:
?php
class TestClass {
   public static $Data = 'This is the data';
}
$Obj = new TestClass ();
$ClassName = get_class ($Obj);
echo $ClassName::$Data;
?
It gives me an error like:
Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM ...
I've found googling that it means that those '::' are unexpected. So, 
How can I get an static member for a class which name is stored in a 
variable?

Thx.
I'd make a method in the class that returned the static variable:
class TestClass
{
public static $data = 'This is the data';
public static function getData ()
{
return self::$data;
}
}
$obj = new TestClass();
echo $obj-getData();
--
Daniel Schierbeck
Help spread Firefox (www.getfirefox.com): 
http://www.spreadfirefox.com/?q=user/registerr=6584

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Getting static member for a class which name is stored in a variable

2004-11-25 Thread Greg Beaver
Francisco M. Marzoa Alonso wrote:
I've code like follows:
?php
class TestClass {
   public static $Data = 'This is the data';
}
$Obj = new TestClass ();
$ClassName = get_class ($Obj);
echo $ClassName::$Data;
?
http://www.php.net/manual/en/language.oop5.reflection.php
?php
class TestClass {
   public static $Data = 'This is the data';
}
$obj = new TestClass;
$a = new ReflectionClass('TestClass');
echo $a-getProperty('Data')-getValue($obj);
?
in PHP 5.1 this should work
?php
class TestClass {
   public static $Data = 'This is the data';
}
$a = new ReflectionClass('TestClass');
echo $a-getProperty('Data')-getValue(null);
?
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php