:PHP의 객체가 값 또는 참조로 전달 되었습니까? 이 코드
<?php
class Foo
{
var $value;
function foo($value)
{
$this->setValue($value);
}
function setValue($value)
{
$this->value=$value;
}
}
class Bar
{
var $foos=array();
function Bar()
{
for ($x=1; $x<=10; $x++)
{
$this->foos[$x]=new Foo("Foo # $x");
}
}
function getFoo($index)
{
return $this->foos[$index];
}
function test()
{
$testFoo=$this->getFoo(5);
$testFoo->setValue("My value has now changed");
}
}
?>
있어서 Bar::test()
실행되고, 그 배열은 실제 푸 # 5가 영향을 받는다, 푸 오브젝트의 배열 푸 # 5의 값을 변경 또는시기를 $testFoo
변수는 함수의 끝 부분에 존재하지 않는 지역 변수 일뿐입니다?
관련 질문 : http://stackoverflow.com/questions/879/php-variables-passed-by-value-or-by-reference. – TSomKes