Skip to content

Commit 4939d2c

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix test Fix bug #81159: Object to int warning when using an object as a string offset Fix bug #81163 indirect vars in __sleep
2 parents 865fb35 + 351629a commit 4939d2c

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type
14441444
return offset;
14451445
}
14461446
zend_illegal_string_offset(dim);
1447-
break;
1447+
return 0;
14481448
}
14491449
case IS_UNDEF:
14501450
ZVAL_UNDEFINED_OP2();
@@ -1460,7 +1460,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type
14601460
goto try_again;
14611461
default:
14621462
zend_illegal_string_offset(dim);
1463-
break;
1463+
return 0;
14641464
}
14651465

14661466
offset = zval_get_long_func(dim, /* is_strict */ false);
@@ -2424,7 +2424,8 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
24242424
return;
24252425
}
24262426
zend_illegal_string_offset(dim);
2427-
break;
2427+
ZVAL_NULL(result);
2428+
return;
24282429
}
24292430
case IS_UNDEF:
24302431
ZVAL_UNDEFINED_OP2();
@@ -2442,7 +2443,8 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
24422443
goto try_string_offset;
24432444
default:
24442445
zend_illegal_string_offset(dim);
2445-
break;
2446+
ZVAL_NULL(result);
2447+
return;
24462448
}
24472449

24482450
offset = zval_get_long_func(dim, /* is_strict */ false);

0 commit comments

Comments
 (0)