Jump to content

OOP Utilizing objects in classes.


Omirion

Recommended Posts

You can't instantiate an object that way. You'll need to instantiate the Moo object inside the foo object's constructor. Here's an example on how to do what you're trying to do:

 

class foo {
public function sayHello() {
	echo 'Hello';
}
}

class bar {
protected $foo;

public function __construct() {
	$this->foo = new foo();
}

public function someMethod() {
	$this->foo->sayHello();
}
}

$instance = new bar();
$instance->someMethod();

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.