Skip to content

Commit 1b171bb

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix GH-15918: Assertion failure in ext/spl/spl_fixedarray.c
2 parents 7e6e712 + 9774ced commit 1b171bb

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ PHP NEWS
4444
. Fixed bug GH-15711 (SoapClient can't convert BackedEnum to scalar value).
4545
(nielsdos)
4646

47+
- SPL:
48+
. Fixed bug GH-15918 (Assertion failure in ext/spl/spl_fixedarray.c).
49+
(nielsdos)
50+
4751
- Standard:
4852
. Add support for backed enums in http_build_query(). (ilutov)
4953

ext/spl/spl_array.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
964964
}
965965
} else {
966966
zend_object_get_properties_t handler = Z_OBJ_HANDLER_P(array, get_properties);
967-
if (handler != zend_std_get_properties) {
967+
if (handler != zend_std_get_properties || Z_OBJ_HANDLER_P(array, get_properties_for)) {
968968
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0,
969969
"Overloaded object of type %s is not compatible with %s",
970970
ZSTR_VAL(Z_OBJCE_P(array)->name), ZSTR_VAL(intern->std.ce->name));
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
--TEST--
2-
SplFixedArray properties is compatible with ArrayObject
2+
SplFixedArray properties is incompatible with ArrayObject
33
--FILE--
44
<?php
55
$ao = new ArrayObject([1, 2, 3]);
66
$fixedArray = new SplFixedArray(1);
77
$fixedArray[0] = new SplDoublyLinkedList();
8-
$ao->exchangeArray($fixedArray);
9-
$ao[0] = new stdClass();
10-
var_dump($ao);
8+
try {
9+
// See GH-15918: this *should* fail to not break invariants
10+
$ao->exchangeArray($fixedArray);
11+
} catch (InvalidArgumentException $e) {
12+
echo $e->getMessage(), "\n";
13+
}
1114
?>
1215
--EXPECT--
13-
object(ArrayObject)#1 (1) {
14-
["storage":"ArrayObject":private]=>
15-
object(SplFixedArray)#2 (2) {
16-
[0]=>
17-
object(SplDoublyLinkedList)#3 (2) {
18-
["flags":"SplDoublyLinkedList":private]=>
19-
int(0)
20-
["dllist":"SplDoublyLinkedList":private]=>
21-
array(0) {
22-
}
23-
}
24-
["0"]=>
25-
object(stdClass)#4 (0) {
26-
}
27-
}
28-
}
16+
Overloaded object of type SplFixedArray is not compatible with ArrayObject

ext/spl/tests/gh15918.phpt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-15918 (Assertion failure in ext/spl/spl_fixedarray.c)
3+
--FILE--
4+
<?php
5+
$foo = new SplFixedArray(5);
6+
try {
7+
$arrayObject = new ArrayObject($foo);
8+
} catch (InvalidArgumentException $e) {
9+
echo $e->getMessage(), "\n";
10+
}
11+
?>
12+
--EXPECT--
13+
Overloaded object of type SplFixedArray is not compatible with ArrayObject

0 commit comments

Comments
 (0)