I am new to object php, I have the following concern:
is it possible to have one class included inside another class, and use it’s method like:
in Anotherclass.php file
class Another
{
public $value = '';
public function setValue($newvalue)
{
$this->value=$newvalue;
}
public function getValue()
{
return $this->value;
}
}
in Bootstrap.php file:
require(Another.inc)
class Bootstrap
{
public static function main($value)
{
$obj = new Another();
$obj-> setValue($value)
echo $obj->getValue();
}
}
Bootstrap::main("test");
so when I call Bootstrap::main(“test”) in the Bootstrap.php file, can I get the output which is “test”? Any help will be greatly appreciated!
You missed a semi-colon but with that fixed it works fine :
should be
and called with
Bootstrap::main('test');will outputtestWorking example with both classes in the same file : http://codepad.org/yHyNAoT5
I would suggest making
private– this forces the use of the getter and setter methods rather than accessing directly