문제

I am just exploring how Symbol Tables and Variable Containers work together with references. And I found out that

<?php    
   $a = & $b;    
?>

doesn't throw a Notice saying "Undefined variable: b in...", while

<?php    
   $a = $b;    
?>

does.

Why?

도움이 되었습니까?

해결책

From the manual: http://php.net/manual/en/language.references.whatdo.php

Note: If you assign, pass, or return an undefined variable by reference, it will get created.

As to why, I would just be speculating that php allocates the memory and assigns $a and $b to both look at that spot in memory. It is a documented behavior though.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top