cvs: ZendEngine2 / zend_execute_API.c zend_hash.c zend_hash.h /tests bug35509.phpt

From: Date: Mon, 05 Dec 2005 08:56:32 +0000
Subject: cvs: ZendEngine2 / zend_execute_API.c zend_hash.c zend_hash.h /tests bug35509.phpt
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-4422@lists.php.net to get a copy of this message
dmitry Mon Dec 5 03:56:32 2005 EDT Modified files: /ZendEngine2 zend_execute_API.c zend_hash.c zend_hash.h /ZendEngine2/tests bug35509.phpt Log: Fixed bug #35509 (string constant as array key has different behavior inside object) http://cvs.php.net/diff.php/ZendEngine2/zend_execute_API.c?r1=1.344&r2=1.345&ty=u Index: ZendEngine2/zend_execute_API.c diff -u ZendEngine2/zend_execute_API.c:1.344 ZendEngine2/zend_execute_API.c:1.345 --- ZendEngine2/zend_execute_API.c:1.344 Thu Nov 24 06:32:44 2005 +++ ZendEngine2/zend_execute_API.c Mon Dec 5 03:56:31 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute_API.c,v 1.344 2005/11/24 11:32:44 dmitry Exp $ */ +/* $Id: zend_execute_API.c,v 1.345 2005/12/05 08:56:31 dmitry Exp $ */ #include <stdio.h> #include <signal.h> @@ -523,28 +523,10 @@ *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; http://cvs.php.net/diff.php/ZendEngine2/zend_hash.c?r1=1.124&r2=1.125&ty=u Index: ZendEngine2/zend_hash.c diff -u ZendEngine2/zend_hash.c:1.124 ZendEngine2/zend_hash.c:1.125 --- ZendEngine2/zend_hash.c:1.124 Mon Aug 15 10:39:18 2005 +++ ZendEngine2/zend_hash.c Mon Dec 5 03:56:31 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_hash.c,v 1.124 2005/08/15 14:39:18 dmitry Exp $ */ +/* $Id: zend_hash.c,v 1.125 2005/12/05 08:56:31 dmitry Exp $ */ #include "zend.h" #include "zend_operators.h" @@ -1694,6 +1694,24 @@ 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 @@ 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) { http://cvs.php.net/diff.php/ZendEngine2/zend_hash.h?r1=1.79&r2=1.80&ty=u Index: ZendEngine2/zend_hash.h diff -u ZendEngine2/zend_hash.h:1.79 ZendEngine2/zend_hash.h:1.80 --- ZendEngine2/zend_hash.h:1.79 Thu Aug 11 19:34:57 2005 +++ ZendEngine2/zend_hash.h Mon Dec 5 03:56:31 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_hash.h,v 1.79 2005/08/11 23:34:57 andrei Exp $ */ +/* $Id: zend_hash.h,v 1.80 2005/12/05 08:56:31 dmitry Exp $ */ #ifndef ZEND_HASH_H #define ZEND_HASH_H @@ -339,11 +339,13 @@ 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 */ http://cvs.php.net/diff.php/ZendEngine2/tests/bug35509.phpt?r1=1.1&r2=1.2&ty=u Index: ZendEngine2/tests/bug35509.phpt diff -u /dev/null ZendEngine2/tests/bug35509.phpt:1.2 --- /dev/null Mon Dec 5 03:56:32 2005 +++ ZendEngine2/tests/bug35509.phpt Mon Dec 5 03:56:32 2005 @@ -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 +)

« previous php.zend-engine.cvs (#4422) next »