From 7aaff40de5a1dd73186bc4e13dcf10ae2dbf3313 Mon Sep 17 00:00:00 2001
From: Dmitry Stogov <dmitry@php.net>
Date: Mon, 5 Dec 2005 08:56:32 +0000
Subject: [PATCH] Fixed bug #35509 (string constant as array key has different
 behavior inside object)

---
 Zend/tests/bug35509.phpt | 31 +++++++++++++++++++++++++++++++
 Zend/zend_execute_API.c  | 24 +++---------------------
 Zend/zend_hash.c         | 25 +++++++++++++++++++++++++
 Zend/zend_hash.h         |  2 ++
 4 files changed, 61 insertions(+), 21 deletions(-)
 create mode 100755 Zend/tests/bug35509.phpt

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 25e828c44e..5aecf8671f 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -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;
diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c
index bfe203d088..dfd5f8b7f0 100644
--- a/Zend/zend_hash.c
+++ b/Zend/zend_hash.c
@@ -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)
 {
diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h
index f0aa3e6034..c58822d9a0 100644
--- a/Zend/zend_hash.h
+++ b/Zend/zend_hash.h
@@ -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 */
 
-- 
2.40.0