object arguments of call_user_func_array are being iterated
Example code to compare on hhvm and php5
<?php
function f() { var_dump(func_get_args()); }
class C implements IteratorAggregate {
private $arr;
function __construct(array $arr) {$this->arr = $arr;}
function getIterator() { return new ArrayIterator($this->arr); }
}
$a = array('a' => 1, 'b' => 2, 3, 4, 5);
$c = new C($a);
call_user_func_array('f', new stdClass()); // non-Traversable
call_user_func_array('f', $c); // Traversable via IteratorAggregate
call_user_func_array('f', new ArrayIterator($a)); // Traversable via Iterator
http://3v4l.org/ktsfL
PHP 5.5 complains that "call_user_func_array() expects parameter 2 to be array, object given" whereas hhvm iterates the properties of the object
This is intended, no? It would defeat the purpose of maps/vectors if they couldn't be passed around where arrays are used.
Looks like this will be fixed in #3942 (see type annotation).
#3942 won't fix this, it's being casted explicitly in ExecutionContext::doFCallArrayTC / ExecutionContext::iopFCallArray.
This is still an issue, the function is typed as taking an array but the FCallArray bytecode still doesn't require an array. So anywhere we can't statically infer that call_user_func_array is being invoked we fallback to the builtin which will fail on non-arrays. That being said allowing an iterable doesn't seem unreasonable. The right answer here may be to just allow call_user_func_array to take iterables.
https://3v4l.org/r6nM3
I am going over old issues on this repository, to see which ones apply to the current versions of hhvm.
Hhvm now matches the PHP 7 behavior: Warning: call_user_func_array() expects parameter 2 to be an array or collection, object given in /file.php on line 21
This could theoretically throw a TypeError, but it nolonger iterates over the object properties. There could be a new issue created for this.