Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Zend/tests/bug81159.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Bug #81159: Object to int warning when using an object as a string offset
--FILE--
<?php

$s = 'Hello';
$o = new stdClass();
try {
$s[$o] = 'A';
} catch (\Throwable $e) {
echo $e->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
2 changes: 0 additions & 2 deletions Zend/tests/offset_string.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down