]> granicus.if.org Git - php/commitdiff
Fixed bug #35509 (string constant as array key has different behavior inside object)
authorDmitry Stogov <dmitry@php.net>
Mon, 5 Dec 2005 08:56:32 +0000 (08:56 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 5 Dec 2005 08:56:32 +0000 (08:56 +0000)
Zend/tests/bug35509.phpt [new file with mode: 0755]
Zend/zend_execute_API.c
Zend/zend_hash.c
Zend/zend_hash.h

diff --git a/Zend/tests/bug35509.phpt b/Zend/tests/bug35509.phpt
new file mode 100755 (executable)
index 0000000..6cb54c0
--- /dev/null
@@ -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
+)
index 25e828c44e6d8d0174c2f911dd483c9c622a09ff..5aecf8671f004bf2fb76064330daf26c9e44f2dd 100644 (file)
@@ -523,28 +523,10 @@ 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(Z_STRVAL(const_value), Z_STRLEN(const_value), &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, Z_STRVAL(const_value), Z_STRLEN(const_value)+1, 0);
-                                       }
+                               case IS_STRING:
+                               case IS_UNICODE:
+                                       zend_u_symtable_update_current_key(p->value.ht, Z_TYPE(const_value), Z_UNIVAL(const_value), Z_UNILEN(const_value)+1);
                                        break;
-                               }
-                               case IS_UNICODE: {
-                                       long lval;
-                                       double dval;
-
-                                       if (is_numeric_unicode(Z_USTRVAL(const_value), Z_USTRLEN(const_value), &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_UNICODE, Z_USTRVAL(const_value), Z_USTRLEN(const_value)+1, 0);
-                                       }
-                                       break;
-                               }
                                case IS_BINARY:
                                        zend_hash_update_current_key(p->value.ht, HASH_KEY_IS_BINARY, Z_STRVAL(const_value), Z_STRLEN(const_value)+1, 0);
                                        break;
index bfe203d0888bf307f402c7a0fae4205496540d96..dfd5f8b7f06d15e59aa3210cf509e5ee3edd81cc 100644 (file)
@@ -1694,6 +1694,24 @@ ZEND_API int zend_u_symtable_exists(HashTable *ht, zend_uchar type, void *arKey,
        return zend_u_hash_exists(ht, type, arKey, nKeyLength);
 }
 
+
+ZEND_API int zend_u_symtable_update_current_key(HashTable *ht, zend_uchar type, void *arKey, uint nKeyLength)
+{
+       zend_uchar key_type;
+
+       if (type == IS_STRING) {
+               key_type = HASH_KEY_IS_STRING;  
+               HANDLE_NUMERIC((char*)arKey, nKeyLength, zend_hash_update_current_key(ht, HASH_KEY_IS_LONG, NULL, 0, idx));
+       } else if (type == IS_UNICODE) {
+               key_type = HASH_KEY_IS_UNICODE; 
+               HANDLE_U_NUMERIC((UChar*)arKey, nKeyLength, zend_hash_update_current_key(ht, HASH_KEY_IS_LONG, NULL, 0, idx));
+       } else {
+               key_type = HASH_KEY_IS_BINARY;  
+       }
+       return zend_hash_update_current_key(ht, key_type, arKey, nKeyLength, 0);
+}
+
+
 ZEND_API int zend_symtable_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest)
 {
        HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_update(ht, idx, pData, nDataSize, pDest));
@@ -1721,6 +1739,13 @@ ZEND_API int zend_symtable_exists(HashTable *ht, char *arKey, uint nKeyLength)
        return zend_hash_exists(ht, arKey, nKeyLength);
 }
 
+
+ZEND_API 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);
+}
+
 #if ZEND_DEBUG
 void zend_hash_display_pListTail(HashTable *ht)
 {
index f0aa3e6034c3da6853d39c644fc4dab595ad288b..c58822d9a00009e1b410ce524409d755712086e6 100644 (file)
@@ -339,11 +339,13 @@ ZEND_API int zend_symtable_update(HashTable *ht, char *arKey, uint nKeyLength, v
 ZEND_API int zend_symtable_del(HashTable *ht, char *arKey, uint nKeyLength);
 ZEND_API int zend_symtable_find(HashTable *ht, char *arKey, uint nKeyLength, void **pData);
 ZEND_API int zend_symtable_exists(HashTable *ht, char *arKey, uint nKeyLength);
+ZEND_API int zend_symtable_update_current_key(HashTable *ht, char *arKey, uint nKeyLength);
 
 ZEND_API int zend_u_symtable_update(HashTable *ht, zend_uchar type, void *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest);
 ZEND_API int zend_u_symtable_del(HashTable *ht, zend_uchar type, void *arKey, uint nKeyLength);
 ZEND_API int zend_u_symtable_find(HashTable *ht, zend_uchar type, void *arKey, uint nKeyLength, void **pData);
 ZEND_API int zend_u_symtable_exists(HashTable *ht, zend_uchar type, void *arKey, uint nKeyLength);
+ZEND_API int zend_u_symtable_update_current_key(HashTable *ht, zend_uchar type, void *arKey, uint nKeyLength);
 
 #endif                                                 /* ZEND_HASH_H */