diff --git a/Zend/tests/bug81159.phpt b/Zend/tests/bug81159.phpt new file mode 100644 index 0000000000000..d16deafbf5b93 --- /dev/null +++ b/Zend/tests/bug81159.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #81159: Object to int warning when using an object as a string offset +--FILE-- +getMessage(), "\n"; +} +try { + var_dump($s[$o]); +} catch (\Throwable $e) { + echo $e->getMessage(), "\n"; +} +?> +--EXPECT-- +Cannot access offset of type stdClass on string +Cannot access offset of type stdClass on string diff --git a/Zend/tests/offset_string.phpt b/Zend/tests/offset_string.phpt index f14c63af5de79..a32a682656896 100644 --- a/Zend/tests/offset_string.phpt +++ b/Zend/tests/offset_string.phpt @@ -68,8 +68,6 @@ string(1) "i" Warning: String offset cast occurred in %s on line %d string(1) "S" Cannot access offset of type resource on string - -Warning: Object of class stdClass could not be converted to int in %s on line %d Cannot access offset of type stdClass on string Cannot access offset of type array on string Done diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index cd2ce042f9b68..2bd2297faac30 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1384,7 +1384,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type return offset; } zend_illegal_string_offset(dim); - break; + return 0; } case IS_UNDEF: ZVAL_UNDEFINED_OP2(); @@ -1399,7 +1399,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type goto try_again; default: zend_illegal_string_offset(dim); - break; + return 0; } offset = zval_get_long_func(dim); @@ -2384,7 +2384,8 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z return; } zend_illegal_string_offset(dim); - break; + ZVAL_NULL(result); + return; } case IS_UNDEF: ZVAL_UNDEFINED_OP2(); @@ -2401,7 +2402,8 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z goto try_string_offset; default: zend_illegal_string_offset(dim); - break; + ZVAL_NULL(result); + return; } offset = zval_get_long_func(dim);