com php-src: Fix bug #64555: foreach no longer copies keys if they are interned: NEWS Zend/tests/bug64555.phpt Zend/zend_hash.c
| From: | Nikita Popov | Date: | Wed, 03 Apr 2013 18:29:19 +0000 |
| Subject: | com php-src: Fix bug #64555: foreach no longer copies keys if they are interned: NEWS Zend/tests/bug64555.phpt Zend/zend_hash.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-71846@lists.php.net to get a copy of this message | ||
Commit: 1f34ccbe34783f5671bc2a68e7299cea7493c82b
Author: Nikita Popov <nikic@php.net> Wed, 3 Apr 2013 20:29:19 +0200
Parents: 42f94aa9783c72411336dfc39a8b7335cb45854c
Branches: PHP-5.5 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1f34ccbe34783f5671bc2a68e7299cea7493c82b
Log:
Fix bug #64555: foreach no longer copies keys if they are interned
Bugs:
https://bugs.php.net/64555
Changed paths:
M NEWS
A Zend/tests/bug64555.phpt
M Zend/zend_hash.c
Diff:
diff --git a/NEWS b/NEWS
index 7e83b30..974df5e 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ PHP NEWS
- Core:
. Fixed bug #64565 (copy doesn't report failure on partial copy). (Remi)
+ . Fixed bug #64555 (foreach no longer copies keys if they are interned).
+ (Nikita Popov)
- CURL:
. Added CURL_WRAPPERS_ENABLE constant. (Laruence)
diff --git a/Zend/tests/bug64555.phpt b/Zend/tests/bug64555.phpt
new file mode 100644
index 0000000..d5226af
--- /dev/null
+++ b/Zend/tests/bug64555.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Bug #64555: Array key within interned string gets wrong hash value
+--FILE--
+<?php
+
+class Foo {
+ protected $unsetme = 1;
+ protected $keepme = 2;
+
+ public function test() {
+ $a = get_object_vars($this);
+
+ foreach ($a as $k => $v) {
+ if ($k == 'unsetme') {
+ echo "Unsetting: $k\n";
+ unset($a[$k]);
+ } else if ($k == 'keepme') {
+ echo "Changing: $k\n";
+ $a[$k] = 42;
+ $a['keepme'] = 43;
+ }
+ }
+
+ var_dump($a, array_keys($a));
+ }
+}
+
+$f = new Foo;
+$f->test();
+
+?>
+--EXPECT--
+Unsetting: unsetme
+Changing: keepme
+array(1) {
+ ["keepme"]=>
+ int(43)
+}
+array(1) {
+ [0]=>
+ string(6) "keepme"
+}
diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c
index bca47b3..27b603e 100644
--- a/Zend/zend_hash.c
+++ b/Zend/zend_hash.c
@@ -1182,7 +1182,7 @@ ZEND_API void zend_hash_get_current_key_zval_ex(const HashTable *ht, zval
*key,
Z_TYPE_P(key) = IS_NULL;
} else if (p->nKeyLength) {
Z_TYPE_P(key) = IS_STRING;
- Z_STRVAL_P(key) = IS_INTERNED(p->arKey) ? (char *) p->arKey : estrndup(p->arKey,
p->nKeyLength - 1);
+ Z_STRVAL_P(key) = estrndup(p->arKey, p->nKeyLength - 1);
Z_STRLEN_P(key) = p->nKeyLength - 1;
} else {
Z_TYPE_P(key) = IS_LONG;