Browse Source

Fixed bug #35509 (string constant as array key has different behavior inside object)

migration/RELEASE_1_0_0
Dmitry Stogov 20 years ago
parent
commit
7aaff40de5
  1. 31
      Zend/tests/bug35509.phpt
  2. 24
      Zend/zend_execute_API.c
  3. 25
      Zend/zend_hash.c
  4. 2
      Zend/zend_hash.h

31
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
)

24
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;

25
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)
{

2
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 */

Loading…
Cancel
Save