xploita Posted April 6, 2007 Share Posted April 6, 2007 hello, using php4 i'm having a problem gathering all my classes together.i have three classes(ErrorHandler,i18n and templateEngine),placed in separate files. should i create one class and inherit from it or what? another thing,the following example is not working.any ideas why not? <?php class A { var $name = "name"; function getname() { return $this->name; } } class B { function bar() { $name = A::getname(); echo $name; } } ?> Link to comment https://forums.phpfreaks.com/topic/45918-gather-classes-together/ Share on other sites More sharing options...
utexas_pjm Posted April 6, 2007 Share Posted April 6, 2007 You are calling the method from a static context. You need to instantiate the object like this: <?php class A { var $name = "name"; function getname() { return $this->name; } } class B { function bar() { $a = new A(); $name = $a->getname(); echo $name; } } ?> Best, Patrick Link to comment https://forums.phpfreaks.com/topic/45918-gather-classes-together/#findComment-223084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.