我想你想訪問實例變量不是函數變量。因此,這將是這樣的:
$var = $object->function()->instance_variable;
對於這個工作,你的函數應該與實例變量返回一個對象,那麼只有你將能夠實現這一目標。
爲了更清楚看到下面的例子:
<?php
class Name
{
public $fname, $lname;
function __construct($fname, $lname)
{
$this->fname = $fname;
$this->lname = $lname;
}
}
class Person
{
private $name;
public function __construct($fname, $lname)
{
$this->setName($fname, $lname);
}
public function getName()
{
return $this->name;
}
private function setName($fname, $lname)
{
$this->name = new Name($fname, $lname);
}
}
$p = new Person('Raj', 'Mishra');
$name = $p->getName();
print $var = $name->fname; // $var = $object->instance_variable1;
print " ";
print $var = $p->getName()->lname; // $var = $object->function()->instance_variable2;
?>
你能提供有關此 –
你的意思instance_variable更多信息? –