From:             arpad
Operating system: 
PHP version:      5.5.0beta1
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:foreach no longer copies keys if they seem to be interned

Description:
------------
Foreach used to always copy string keys:
    key_type = zend_hash_get_current_key_ex(fe_ht, &str_key, &str_key_len,
&int_key, 1, NULL);

Since fcc6611de9054327441786e52444b5f8eecdd525 it instead uses:
    zend_hash_get_current_key_zval(fe_ht, key);

This only copies string keys if IS_INTERNED(), however in some cases (at
least in get_object_vars() like in the test script) the key name is an
unmangled property name which is *within* an interned string. So
IS_INTERNED is true but INTERNED_LEN and INTERNED_HASH are nonsense.

The later unset and assignment in the test script use the nonsense
INTERNED_HASH.

The simple fix is to make get_object_vars() copy the property names (as in
the attached patch) but it's quite possible that other code has been broken
in the same way, so the safer fix might be to force the copy again.


Test script:
---------------
https://gist.github.com/arraypad/5280321

Expected result:
----------------
Unsetting: unsetme
Changing: keepme
array(1) {
  ["keepme"]=>
  int(43)
}
array(1) {
  [0]=>
  string(6) "keepme"
}

Actual result:
--------------
Unsetting: unsetme
Changing: keepme
array(3) {
  ["unsetme"]=>
  int(1)
  ["keepme"]=>
  int(43)
  ["keepme"]=>
  int(42)
}
array(3) {
  [0]=>
  string(7) "unsetme"
  [1]=>
  string(6) "keepme"
  [2]=>
  string(6) "keepme"
}

-- 
Edit bug report at https://bugs.php.net/bug.php?id=64555&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64555&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64555&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64555&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64555&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64555&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64555&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64555&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64555&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64555&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64555&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64555&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64555&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64555&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64555&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64555&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64555&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64555&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64555&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64555&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64555&r=mysqlcfg

Reply via email to