|
Posted by Markus Ernst on 05/31/06 10:04
Hi
In order to make static class variables accessible in a clean way I try
to write a method in the base class, as shown in this example:
<?php
class baseclass
{
function get_static($varname) {
return $$varname; // here's my problem
}
}
class childclass extends baseclass
{
var $types = array('text', 'password', 'hidden');
}
print_r(childclass::get_static('types'));
?>
This throws a notice:
-> Notice: Undefined variable: types in test.php on line 5
Some modifications I tried on the return statement:
return $this->$varname;
-> Notice: Undefined property: this in test.php on line 5
return self::$varname;
return self::$$varname;
return self::${$varname};
-> Parse error: parse error, unexpected ';', expecting '(' in test.php
on line 5
I encountered that the same errors occur if no inheritance is used, this
does not work either (with the same modifications as above):
<?php
class childclass
{
var $types = array('text', 'password', 'hidden');
function get_types() {
return $types;
}
}
print_r(childclass::get_types());
?>
I wonder if I try to do something inappropriate, or if there is just
something I am missing?
--
Markus
Navigation:
[Reply to this message]
|