Skip to content

Commit a4ee3cb

Browse files
committed
- Fix Bug #40872 (inconsistency in offsetSet, offsetExists treatment of string enclosed integers)
1 parent cd7a656 commit a4ee3cb

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

ext/spl/spl_array.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
460460
{
461461
spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
462462
long index;
463-
zval *rv;
463+
zval *rv, **tmp;
464464

465465
if (check_inherited && intern->fptr_offset_has) {
466466
SEPARATE_ARG_IF_REF(offset);
@@ -480,9 +480,7 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
480480
case IS_STRING:
481481
case IS_UNICODE:
482482
if (check_empty) {
483-
zval **tmp;
484-
HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
485-
if (zend_u_hash_find(ht, Z_TYPE_P(offset), Z_UNIVAL_P(offset), Z_UNILEN_P(offset)+1, (void **) &tmp) != FAILURE && zend_is_true(*tmp)) {
483+
if (zend_symtable_find(spl_array_get_hash_table(intern, 0 TSRMLS_CC), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void **) &tmp) != FAILURE && zend_is_true(*tmp)) {
486484
return 1;
487485
}
488486
return 0;

ext/spl/tests/bug40872.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #40872 (inconsistency in offsetSet, offsetExists treatment of string enclosed integers)
3+
--FILE--
4+
<?php
5+
class Project {
6+
public $id;
7+
8+
function __construct($id) {
9+
$this->id = $id;
10+
}
11+
}
12+
13+
class ProjectsList extends ArrayIterator {
14+
public function add(Project $item) {
15+
$this->offsetSet($item->id, $item);
16+
}
17+
}
18+
19+
$projects = new ProjectsList();
20+
$projects->add(new Project('1'));
21+
$projects->add(new Project(2));
22+
23+
var_dump($projects->offsetExists(1));
24+
var_dump($projects->offsetExists('2'));
25+
?>
26+
===DONE===
27+
--EXPECT--
28+
bool(true)
29+
bool(true)
30+
===DONE===

0 commit comments

Comments
 (0)