@@ -578,25 +578,26 @@ static void spl_array_unset_dimension(zend_object *object, zval *offset) /* {{{
578
578
spl_array_unset_dimension_ex (1 , object , offset );
579
579
} /* }}} */
580
580
581
- static int spl_array_has_dimension_ex (int check_inherited , zend_object * object , zval * offset , int check_empty ) /* {{{ */
581
+ static int spl_array_has_dimension_ex (bool check_inherited , zend_object * object , zval * offset , int check_empty ) /* {{{ */
582
582
{
583
583
spl_array_object * intern = spl_array_from_obj (object );
584
584
zval rv , * value = NULL , * tmp ;
585
585
586
586
if (check_inherited && intern -> fptr_offset_has ) {
587
587
zend_call_method_with_1_params (object , object -> ce , & intern -> fptr_offset_has , "offsetExists" , & rv , offset );
588
588
589
- if (zend_is_true (& rv )) {
590
- zval_ptr_dtor (& rv );
591
- if (check_empty != 1 ) {
592
- return 1 ;
593
- } else if (intern -> fptr_offset_get ) {
594
- value = spl_array_read_dimension_ex (1 , object , offset , BP_VAR_R , & rv );
595
- }
596
- } else {
589
+ if (!zend_is_true (& rv )) {
597
590
zval_ptr_dtor (& rv );
598
591
return 0 ;
599
592
}
593
+ zval_ptr_dtor (& rv );
594
+
595
+ /* For isset calls we don't need to check the value, so return early */
596
+ if (!check_empty ) {
597
+ return 1 ;
598
+ } else if (intern -> fptr_offset_get ) {
599
+ value = spl_array_read_dimension_ex (1 , object , offset , BP_VAR_R , & rv );
600
+ }
600
601
}
601
602
602
603
if (!value ) {
@@ -615,33 +616,34 @@ static int spl_array_has_dimension_ex(int check_inherited, zend_object *object,
615
616
tmp = zend_hash_index_find (ht , key .h );
616
617
}
617
618
618
- if (tmp ) {
619
- if (check_empty == 2 ) {
620
- return 1 ;
621
- }
622
- } else {
619
+ if (!tmp ) {
623
620
return 0 ;
624
621
}
625
622
623
+ /* check_empty is only equal to 2 if it is called from offsetExists on this class,
624
+ * where it needs to report an offset exists even if the value is null */
625
+ if (check_empty == 2 ) {
626
+ return 1 ;
627
+ }
628
+
626
629
if (check_empty && check_inherited && intern -> fptr_offset_get ) {
627
630
value = spl_array_read_dimension_ex (1 , object , offset , BP_VAR_R , & rv );
628
631
} else {
629
632
value = tmp ;
630
633
}
631
634
}
632
635
633
- {
634
- bool result = check_empty ? zend_is_true (value ) : Z_TYPE_P (value ) != IS_NULL ;
635
- if (value == & rv ) {
636
- zval_ptr_dtor (& rv );
637
- }
638
- return result ;
636
+ if (value == & rv ) {
637
+ zval_ptr_dtor (& rv );
639
638
}
639
+
640
+ /* empty() check the value is not falsy, isset() only check it is not null */
641
+ return check_empty ? zend_is_true (value ) : Z_TYPE_P (value ) != IS_NULL ;
640
642
} /* }}} */
641
643
642
644
static int spl_array_has_dimension (zend_object * object , zval * offset , int check_empty ) /* {{{ */
643
645
{
644
- return spl_array_has_dimension_ex (1 , object , offset , check_empty );
646
+ return spl_array_has_dimension_ex (/* check_inherited */ true , object , offset , check_empty );
645
647
} /* }}} */
646
648
647
649
/* {{{ Returns whether the requested $index exists. */
@@ -651,7 +653,7 @@ PHP_METHOD(ArrayObject, offsetExists)
651
653
if (zend_parse_parameters (ZEND_NUM_ARGS (), "z" , & index ) == FAILURE ) {
652
654
RETURN_THROWS ();
653
655
}
654
- RETURN_BOOL (spl_array_has_dimension_ex (0 , Z_OBJ_P (ZEND_THIS ), index , 2 ));
656
+ RETURN_BOOL (spl_array_has_dimension_ex (/* check_inherited */ false , Z_OBJ_P (ZEND_THIS ), index , 2 ));
655
657
} /* }}} */
656
658
657
659
/* {{{ Returns the value at the specified $index. */
0 commit comments