Skip to content

Commit 925f3c0

Browse files
committed
ext/spl: [WIP] Convert ArrayObject to new API
1 parent f46fb4f commit 925f3c0

20 files changed

+374
-317
lines changed

Zend/tests/offsets/ArrayAccess_container_offset_behaviour.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Cannot unset offset in a non-array variable
102102
OUTPUT;
103103

104104
ob_start();
105-
foreach (['A', 'B'] as $class) {
105+
foreach (['A'] as $class) {
106106
foreach ($offsets as $dimension) {
107107
$container = new $class();
108108
$error = "(new $class())[" . zend_test_var_export($dimension) . '] has different outputs' . "\n";

Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -183,49 +183,6 @@ OUTPUT;
183183

184184
$EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS) . '$/s';
185185

186-
const EXPECTED_OUTPUT_NULL_OFFSET = <<<OUTPUT
187-
Read before write:
188-
189-
Warning: Undefined array key "" in %s on line 8
190-
NULL
191-
Write:
192-
Read:
193-
194-
Warning: Undefined array key "" in %s on line 22
195-
NULL
196-
Read-Write:
197-
198-
Warning: Undefined array key "" in %s on line 29
199-
isset():
200-
bool(false)
201-
empty():
202-
bool(true)
203-
null coalesce:
204-
string(7) "default"
205-
Reference to dimension:
206-
Value of reference:
207-
NULL
208-
Value of container dimension after write to reference (should be int(100) if successful):
209-
int(100)
210-
unset():
211-
Nested read:
212-
213-
Warning: Undefined array key "" in %s on line 74
214-
215-
Warning: Trying to access array offset on null in %s on line 74
216-
NULL
217-
Nested write:
218-
Nested Read-Write:
219-
Nested isset():
220-
bool(true)
221-
Nested empty():
222-
bool(false)
223-
Nested null coalesce:
224-
int(30)
225-
Nested unset():
226-
227-
OUTPUT;
228-
229186
const EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS = <<<OUTPUT
230187
Read before write:
231188
@@ -346,7 +303,6 @@ foreach ($offsets as $dimension) {
346303
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
347304
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
348305
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
349-
&& $varOutput !== EXPECTED_OUTPUT_NULL_OFFSET
350306
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
351307
) {
352308
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_ArrayObject_container_{$failuresNb}.txt", $varOutput);
@@ -377,7 +333,6 @@ foreach ($offsets as $offset) {
377333
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
378334
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
379335
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
380-
&& $varOutput !== EXPECTED_OUTPUT_NULL_OFFSET
381336
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
382337
) {
383338
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_ArrayObject_container_{$failuresNb}.txt", $varOutput);

Zend/tests/offsets/appending_containers.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ string(5) "value"
6565
object(A)#3 (0) {
6666
}
6767
new B() container:
68-
string(12) "B::offsetSet"
69-
NULL
68+
string(9) "B::append"
7069
string(5) "value"
7170
object(B)#4 (1) {
7271
["storage":"ArrayObject":private]=>

Zend/tests/offsets/appending_containers_in_fetch.phpt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,30 @@ Error: Cannot use a scalar value as an array
6060
new stdClass() container:
6161
Error: Cannot use object of type stdClass as array
6262
new ArrayObject() container:
63-
64-
Notice: Indirect modification of overloaded element of ArrayObject has no effect in %s on line %d
65-
Error: ArrayObject::fetchAppend() must return a reference type
63+
object(ArrayObject)#2 (1) {
64+
["storage":"ArrayObject":private]=>
65+
array(1) {
66+
[0]=>
67+
array(1) {
68+
[5]=>
69+
string(5) "value"
70+
}
71+
}
72+
}
6673
new A() container:
6774
string(12) "A::offsetGet"
6875
NULL
6976

7077
Notice: Indirect modification of overloaded element of A has no effect in %s on line %d
7178
Error: Cannot use a scalar value as an array
7279
new B() container:
73-
string(12) "B::offsetGet"
74-
NULL
75-
76-
Notice: Indirect modification of overloaded element of B has no effect in %s on line %d
77-
Error: Cannot use a scalar value as an array
80+
object(B)#4 (1) {
81+
["storage":"ArrayObject":private]=>
82+
array(1) {
83+
[0]=>
84+
array(1) {
85+
[5]=>
86+
string(5) "value"
87+
}
88+
}
89+
}

Zend/tests/offsets/reference_containers_appended.phpt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,14 @@ Error: Cannot use a scalar value as an array
5454
new stdClass() container:
5555
Error: Cannot use object of type stdClass as array
5656
new ArrayObject() container:
57-
58-
Notice: Indirect modification of overloaded element of ArrayObject has no effect in %s on line %d
59-
Error: ArrayObject::fetchAppend() must return a reference type
57+
object(ArrayObject)#2 (1) {
58+
["storage":"ArrayObject":private]=>
59+
array(1) {
60+
[0]=>
61+
&NULL
62+
}
63+
}
64+
NULL
6065
new A() container:
6166
string(12) "A::offsetGet"
6267
NULL
@@ -66,13 +71,11 @@ object(A)#3 (0) {
6671
}
6772
int(5)
6873
new B() container:
69-
string(12) "B::offsetGet"
70-
NULL
71-
72-
Notice: Indirect modification of overloaded element of B has no effect in %s on line %d
7374
object(B)#4 (1) {
7475
["storage":"ArrayObject":private]=>
75-
array(0) {
76+
array(1) {
77+
[0]=>
78+
&NULL
7679
}
7780
}
78-
int(5)
81+
NULL

Zend/zend_execute.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2765,13 +2765,19 @@ static zend_never_inline void zend_fetch_object_dimension_address(zval *result,
27652765
ZVAL_UNDEF(result);
27662766
goto clean_up;
27672767
}
2768-
if (!Z_ISREF_P(retval) && Z_TYPE_P(retval) != IS_OBJECT) {
2768+
if (
2769+
!Z_ISREF_P(retval)
2770+
&& Z_TYPE_P(retval) != IS_OBJECT
2771+
) {
27692772
zend_class_entry *ce = obj->ce;
27702773
zend_throw_error(NULL, "%s::%s() must return a reference type",
27712774
ZSTR_VAL(ce->name), offset ? "offsetFetch" : "fetchAppend");
27722775
ZVAL_UNDEF(result);
27732776
goto clean_up;
27742777
}
2778+
if (result != retval) {
2779+
ZVAL_INDIRECT(result, retval);
2780+
}
27752781
} else {
27762782
zend_use_object_as_array(obj);
27772783
ZVAL_UNDEF(result);

0 commit comments

Comments
 (0)