Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
March 17, 2005, 5:31 pm
rate this thread
I got following problem trying to inherit a variable from another class
$this->obj = $obj;
class test extends Core
$core = new Core
$test = new test
As far as what I would like to get, I would see 'hello', but instead I
get following error:
Fatal error: Access to undeclared static property: Core::$obj (echo
After declaring $obj as public and static I don't get any result as
Is it possible to inherit already initialized variables from a
different class or are there design patterns who could do something
like that? I hope it is clear where I want to go with this..
I am doing this because I can't give the class test any parameters
because it could be extended (class woow extends test). Also the amount
of variables is not certain and there might be lots of classes needing
to inherit the variables. That would mean that I would have to change
every class if a parameter would change..
Re: PHP5: Can a class inherit initialized classvariable from another class?
It seems that you don't want to inherit... but say: a test has_a core.
(lookup composition how to do this)
Btw, if you extend a class, you should have a parent::__constructor();
call explicitely (unlike java).
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info