blueman378 Posted May 13, 2008 Share Posted May 13, 2008 hi guys, can you call a class from within itself? cause i have a function delete subs, and a function delete mains, both inside a class, however i want to link to delete subs when delete mains is called so i dont have to double code it would refrencing it like you refernce from outside work? Link to comment https://forums.phpfreaks.com/topic/105390-calling-a-class-from-within-a-class/ Share on other sites More sharing options...
aschk Posted May 13, 2008 Share Posted May 13, 2008 Your question was a little too abstract for me to understand. Some concrete code of what you're doing would resolve that Link to comment https://forums.phpfreaks.com/topic/105390-calling-a-class-from-within-a-class/#findComment-539751 Share on other sites More sharing options...
Pancake Posted May 14, 2008 Share Posted May 14, 2008 I'm guessing you mean... class someThing { public function someFunction() { /* */ return 'foo'; } } /* */ class anotherThing { protected $do; function __construct() { $this->do = new someThing(); } public function display() { echo $this->do->someFunction(); } } $a = new anotherThing(); $a->display(); Link to comment https://forums.phpfreaks.com/topic/105390-calling-a-class-from-within-a-class/#findComment-540622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.