Skip to content

Commit b4829dc

Browse files
committed
Fix bug #81159: Object to int warning when using an object as a string offset
1 parent 140eca6 commit b4829dc

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

Zend/tests/bug81159.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #81159: Object to int warning when using an object as a string offset
3+
--FILE--
4+
<?php
5+
6+
$s = 'Hello';
7+
$o = new stdClass();
8+
try {
9+
$s[$o] = 'A';
10+
} catch (\Throwable $e) {
11+
echo $e->getMessage(), "\n";
12+
}
13+
try {
14+
var_dump($s[$o]);
15+
} catch (\Throwable $e) {
16+
echo $e->getMessage(), "\n";
17+
}
18+
?>
19+
--EXPECT--
20+
Cannot access offset of type stdClass on string
21+
Cannot access offset of type stdClass on string

Zend/tests/offset_string.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ string(1) "i"
6868
Warning: String offset cast occurred in %s on line %d
6969
string(1) "S"
7070
Cannot access offset of type resource on string
71-
72-
Warning: Object of class stdClass could not be converted to int in %s on line %d
7371
Cannot access offset of type stdClass on string
7472
Cannot access offset of type array on string
7573
Done

Zend/zend_execute.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type
13851385
goto try_again;
13861386
default:
13871387
zend_illegal_string_offset(dim);
1388-
break;
1388+
return 0;
13891389
}
13901390

13911391
offset = zval_get_long_func(dim);
@@ -2387,7 +2387,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
23872387
goto try_string_offset;
23882388
default:
23892389
zend_illegal_string_offset(dim);
2390-
break;
2390+
return;
23912391
}
23922392

23932393
offset = zval_get_long_func(dim);

0 commit comments

Comments
 (0)