diff options
author | Dmitry Stogov <dmitry@php.net> | 2005-12-05 08:56:09 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2005-12-05 08:56:09 +0000 |
commit | 9ee0707cfaa13756e5e36309dbcd9d3edbc5ded3 (patch) | |
tree | 3c176adf9e3ced818a35fbfec73ef794396eec68 | |
parent | 6abf54a4895fb89b5d1f26ecc9c219ee3ea3d371 (diff) | |
download | php-git-9ee0707cfaa13756e5e36309dbcd9d3edbc5ded3.tar.gz |
Fixed bug #35509 (string constant as array key has different behavior inside object)
-rw-r--r-- | NEWS | 2 | ||||
-rwxr-xr-x | Zend/tests/bug35509.phpt | 31 | ||||
-rw-r--r-- | Zend/zend_execute_API.c | 12 | ||||
-rw-r--r-- | Zend/zend_hash.h | 6 |
4 files changed, 41 insertions, 10 deletions
@@ -24,6 +24,8 @@ PHP NEWS - Fixed bug #35543 (php crash when calling non existing method of a class that extends PDO). (Tony) - Fixed bug #35539 (typo in error message for ErrorException). (Tony) +- Fixed bug #35509 (string constant as array key has different behavior inside + object). (Dmitry) - Fixed bug #35508 (PDO fails when unknown fetch mode specified). (Tony) - Fixed bug #35499 (strtotime() does not handle whitespace around the date string). (Ilia) diff --git a/Zend/tests/bug35509.phpt b/Zend/tests/bug35509.phpt new file mode 100755 index 0000000000..6cb54c03e1 --- /dev/null +++ b/Zend/tests/bug35509.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #35509 (string constant as array key has different behavior inside object) +--FILE-- +<?php +class mytest +{ + const classConstant = '01'; + + private $classArray = array( mytest::classConstant => 'value' ); + + public function __construct() + { + print_r($this->classArray); + } +} + +$classtest = new mytest(); + +define( "normalConstant", '01' ); +$normalArray = array( normalConstant => 'value' ); +print_r($normalArray); +?> +--EXPECT-- +Array +( + [01] => value +) +Array +( + [01] => value +) diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 3e0bd367f1..c0d585d835 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -501,17 +501,9 @@ ZEND_API int zval_update_constant(zval **pp, void *arg TSRMLS_DC) *element = new_val; switch (const_value.type) { - case IS_STRING: { - long lval; - double dval; - - if (is_numeric_string(const_value.value.str.val, const_value.value.str.len, &lval, &dval, 0) == IS_LONG) { - zend_hash_update_current_key(p->value.ht, HASH_KEY_IS_LONG, NULL, 0, lval); - } else { - zend_hash_update_current_key(p->value.ht, HASH_KEY_IS_STRING, const_value.value.str.val, const_value.value.str.len+1, 0); - } + case IS_STRING: + zend_symtable_update_current_key(p->value.ht, const_value.value.str.val, const_value.value.str.len+1); break; - } case IS_BOOL: case IS_LONG: zend_hash_update_current_key(p->value.ht, HASH_KEY_IS_LONG, NULL, 0, const_value.value.lval); diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 774c607418..f2b8c9b1f6 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -353,6 +353,12 @@ static inline int zend_symtable_exists(HashTable *ht, char *arKey, uint nKeyLeng return zend_hash_exists(ht, arKey, nKeyLength); } +static inline int zend_symtable_update_current_key(HashTable *ht, char *arKey, uint nKeyLength) +{ + HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_update_current_key(ht, HASH_KEY_IS_LONG, NULL, 0, idx)); + return zend_hash_update_current_key(ht, HASH_KEY_IS_STRING, arKey, nKeyLength, 0); +} + #endif /* ZEND_HASH_H */ /* |