All,

It appears that in our efforts to optimize PHP 7 we've introduced an
inconsistency into array handling. This is demonstrated by this
script: https://3v4l.org/hVcAB

$a = 1;
unset($a);
var_dump(count($GLOBALS), $GLOBALS);

The result is that the count doesn't match the contents of the array.

It also affects objects casted to arrays in certain cases.

Here, the array has 1 element, but should have 0. Trying to access the
"1" element "a" results in a notice.

This means that the count is incorrect. This is due to the fact that
the "a" element follows an IS_INDIRECT type pointing to the other
symbol table.

A potential solution would be to make count() an O(n) operation in the
case that the hashtable is a symbol table or if it has INDIRECT
elements. Meaning that we'd compute the real count at runtime.

This obviously has performance ramifications, but we shouldn't
sacrifice consistency and behavior for performance IMHO. Especially
when it comes to core data structures.

I think this is significant enough to be a blocker to gold and that we
should fix it prior to release.

Thoughts?

Anthony

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to