I'm new to OO in PHP, so maybe this is a dumb question, but I was
wondering if you can declare and use an object from within another
object?
I'd like to do something like this...
class cMyObject {
public function __construct() {
private $foo = new cOtherObject();
}
public function checkWhatever($ input) {
$this->foo->methodInOtherO bject("somethin g");
}
}
This is a very simplistic example that doesn't really relate why I want
to do this, but is it possible?
If it is not possible, why does the following code not throw an error
for an unexpected appearance of the "new" keyword? Bug?
<?php
$myTest = new cObj1;
exit();
class cObj1 {
public function __construct() {
$foo = new cObj2;
}
} // cObj1
class cObj2 {
private $thing;
} // cObj2
?>
My test environment is PHP 5.0.2.
wondering if you can declare and use an object from within another
object?
I'd like to do something like this...
class cMyObject {
public function __construct() {
private $foo = new cOtherObject();
}
public function checkWhatever($ input) {
$this->foo->methodInOtherO bject("somethin g");
}
}
This is a very simplistic example that doesn't really relate why I want
to do this, but is it possible?
If it is not possible, why does the following code not throw an error
for an unexpected appearance of the "new" keyword? Bug?
<?php
$myTest = new cObj1;
exit();
class cObj1 {
public function __construct() {
$foo = new cObj2;
}
} // cObj1
class cObj2 {
private $thing;
} // cObj2
?>
My test environment is PHP 5.0.2.
Comment