Back to questions
JuniorTheoryCommon
What does the program print?
<?php
$a = 5;
$b = $a;
$a = $a + 1;
echo $a, ' ', $b, "\n";6 5
- Expecting
6 6, as if$bwere a second name for$a:$b = $acopies the value at that moment, and a later change to$adoes not reach$b. - Expecting
$a = $a + 1to leave$aat 5: PHP computes$a + 1from the old value and writes the result back into$a.
- What does the program print if
$b = $a;becomes$b = &$a;? - Does
$b = $acopy a large array at once, and when does PHP make the real copy?