PHP return deyimi kullandığınızda, sonuç değere veya başvuruya göre iade edilecektir?
Teşekkürler! Andree.
Görünüşe göre, bu başvuru ile döndürülür. Bu basit kod bunu kanıtı.
<?php
class InsideObject
{
public $variable;
}
class OutsideObject
{
private $insideObject;
public function __construct()
{
$this->insideObject = new InsideObject();
$this->insideObject->variable = '1';
}
public function echoVar()
{
echo $this->insideObject->variable;
}
public function getInsideObject()
{
return $this->insideObject;
}
}
$object = new OutsideObject();
$object->echoVar(); // should be 1
$insideObject = $object->getInsideObject();
$insideObject->variable = '2';
$object->echoVar(); // should be 2