]> granicus.if.org Git - php/commitdiff
- Fix Bug #40872 (inconsistency in offsetSet, offsetExists treatment of string enclos...
authorMarcus Boerger <helly@php.net>
Tue, 20 Mar 2007 20:21:39 +0000 (20:21 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 20 Mar 2007 20:21:39 +0000 (20:21 +0000)
ext/spl/spl_array.c
ext/spl/tests/bug40872.phpt [new file with mode: 0755]

index 42a26670a7f93f2eb035a6ac82eb3edaa6aa689c..d6276612ef4823104f5498557bc5a70d4fa184ed 100755 (executable)
@@ -460,7 +460,7 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
 {
        spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
        long index;
-       zval *rv;
+       zval *rv, **tmp;
 
        if (check_inherited && intern->fptr_offset_has) {
                SEPARATE_ARG_IF_REF(offset);
@@ -480,9 +480,7 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
        case IS_STRING:
        case IS_UNICODE:
                if (check_empty) {
-                       zval **tmp;
-                       HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
-                       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)) {
+                       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)) {
                                return 1;
                        }
                        return 0;
diff --git a/ext/spl/tests/bug40872.phpt b/ext/spl/tests/bug40872.phpt
new file mode 100755 (executable)
index 0000000..a48fe74
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Bug #40872 (inconsistency in offsetSet, offsetExists treatment of string enclosed integers)
+--FILE--
+<?php
+       class Project {
+               public $id;
+
+               function __construct($id) {
+                       $this->id = $id;
+               }
+       }
+
+       class ProjectsList extends ArrayIterator {
+               public function add(Project $item) {
+                       $this->offsetSet($item->id, $item);
+               }
+       }
+
+       $projects = new ProjectsList();
+       $projects->add(new Project('1'));
+       $projects->add(new Project(2));
+
+       var_dump($projects->offsetExists(1));
+       var_dump($projects->offsetExists('2'));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+bool(true)
+===DONE===