hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

list() bug (from phpcompiler test suite)

Open chrisgraham opened this issue 16 years ago • 2 comments

$info = array('coffee', 'brown', 'caffeine');
list($info[2], $info[1], $info[0]) = $info;
// it looks like it reverses the order, but it doesnt. It first overwrites
// $info[0], then later overwrites $info[2] with the value already copied
// from $info[2]
var_dump ($info);

I don't know if anyone cares about this, lol.

[root@ocportal phc]# php test.php
array(3) {
  [0]=>
  string(8) "caffeine"
  [1]=>
  string(5) "brown"
  [2]=>
  string(8) "caffeine"
}
[root@ocportal phc]# sudo $HPHP_HOME/src/hphpi/hphpi -f test.php
array(3) {
  [0]=>
  string(8) "caffeine"
  [1]=>
  string(5) "brown"
  [2]=>
  string(6) "coffee"
}

chrisgraham avatar Jul 18 '10 19:07 chrisgraham

Personally, I'm inclined to file this under "undefined behavior" as the variables is being modified at the same time that it's being read.

I'm going to keep it open for now and discuss with others.

sgolemon avatar Jul 25 '12 20:07 sgolemon

HPHPi was removed from the code base in June 2012. We recommend that developers using HPHPi upgrade to HHVM.

HHVM matches Zend's behavior for your test case.

paroski avatar Oct 12 '12 22:10 paroski