Jump to content

calling a class from within a class


blueman378

Recommended Posts

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

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();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.