Skip to content

Commit

Permalink
ext/spl: [WIP] Convert ArrayObject to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
Girgias committed Jun 6, 2024
1 parent f46fb4f commit 925f3c0
Show file tree
Hide file tree
Showing 20 changed files with 374 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Cannot unset offset in a non-array variable
OUTPUT;

ob_start();
foreach (['A', 'B'] as $class) {
foreach (['A'] as $class) {
foreach ($offsets as $dimension) {
$container = new $class();
$error = "(new $class())[" . zend_test_var_export($dimension) . '] has different outputs' . "\n";
Expand Down
45 changes: 0 additions & 45 deletions Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -183,49 +183,6 @@ OUTPUT;

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

const EXPECTED_OUTPUT_NULL_OFFSET = <<<OUTPUT
Read before write:
Warning: Undefined array key "" in %s on line 8
NULL
Write:
Read:
Warning: Undefined array key "" in %s on line 22
NULL
Read-Write:
Warning: Undefined array key "" in %s on line 29
isset():
bool(false)
empty():
bool(true)
null coalesce:
string(7) "default"
Reference to dimension:
Value of reference:
NULL
Value of container dimension after write to reference (should be int(100) if successful):
int(100)
unset():
Nested read:
Warning: Undefined array key "" in %s on line 74
Warning: Trying to access array offset on null in %s on line 74
NULL
Nested write:
Nested Read-Write:
Nested isset():
bool(true)
Nested empty():
bool(false)
Nested null coalesce:
int(30)
Nested unset():
OUTPUT;

const EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS = <<<OUTPUT
Read before write:
Expand Down Expand Up @@ -346,7 +303,6 @@ foreach ($offsets as $dimension) {
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_NULL_OFFSET
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
) {
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_ArrayObject_container_{$failuresNb}.txt", $varOutput);
Expand Down Expand Up @@ -377,7 +333,6 @@ foreach ($offsets as $offset) {
!preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
&& !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
&& $varOutput !== EXPECTED_OUTPUT_NULL_OFFSET
&& $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
) {
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_ArrayObject_container_{$failuresNb}.txt", $varOutput);
Expand Down
3 changes: 1 addition & 2 deletions Zend/tests/offsets/appending_containers.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ string(5) "value"
object(A)#3 (0) {
}
new B() container:
string(12) "B::offsetSet"
NULL
string(9) "B::append"
string(5) "value"
object(B)#4 (1) {
["storage":"ArrayObject":private]=>
Expand Down
28 changes: 20 additions & 8 deletions Zend/tests/offsets/appending_containers_in_fetch.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,30 @@ Error: Cannot use a scalar value as an array
new stdClass() container:
Error: Cannot use object of type stdClass as array
new ArrayObject() container:

Notice: Indirect modification of overloaded element of ArrayObject has no effect in %s on line %d
Error: ArrayObject::fetchAppend() must return a reference type
object(ArrayObject)#2 (1) {
["storage":"ArrayObject":private]=>
array(1) {
[0]=>
array(1) {
[5]=>
string(5) "value"
}
}
}
new A() container:
string(12) "A::offsetGet"
NULL

Notice: Indirect modification of overloaded element of A has no effect in %s on line %d
Error: Cannot use a scalar value as an array
new B() container:
string(12) "B::offsetGet"
NULL

Notice: Indirect modification of overloaded element of B has no effect in %s on line %d
Error: Cannot use a scalar value as an array
object(B)#4 (1) {
["storage":"ArrayObject":private]=>
array(1) {
[0]=>
array(1) {
[5]=>
string(5) "value"
}
}
}
21 changes: 12 additions & 9 deletions Zend/tests/offsets/reference_containers_appended.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ Error: Cannot use a scalar value as an array
new stdClass() container:
Error: Cannot use object of type stdClass as array
new ArrayObject() container:

Notice: Indirect modification of overloaded element of ArrayObject has no effect in %s on line %d
Error: ArrayObject::fetchAppend() must return a reference type
object(ArrayObject)#2 (1) {
["storage":"ArrayObject":private]=>
array(1) {
[0]=>
&NULL
}
}
NULL
new A() container:
string(12) "A::offsetGet"
NULL
Expand All @@ -66,13 +71,11 @@ object(A)#3 (0) {
}
int(5)
new B() container:
string(12) "B::offsetGet"
NULL

Notice: Indirect modification of overloaded element of B has no effect in %s on line %d
object(B)#4 (1) {
["storage":"ArrayObject":private]=>
array(0) {
array(1) {
[0]=>
&NULL
}
}
int(5)
NULL
8 changes: 7 additions & 1 deletion Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -2765,13 +2765,19 @@ static zend_never_inline void zend_fetch_object_dimension_address(zval *result,
ZVAL_UNDEF(result);
goto clean_up;
}
if (!Z_ISREF_P(retval) && Z_TYPE_P(retval) != IS_OBJECT) {
if (
!Z_ISREF_P(retval)
&& Z_TYPE_P(retval) != IS_OBJECT
) {
zend_class_entry *ce = obj->ce;
zend_throw_error(NULL, "%s::%s() must return a reference type",
ZSTR_VAL(ce->name), offset ? "offsetFetch" : "fetchAppend");
ZVAL_UNDEF(result);
goto clean_up;
}
if (result != retval) {
ZVAL_INDIRECT(result, retval);
}
} else {
zend_use_object_as_array(obj);
ZVAL_UNDEF(result);
Expand Down
Loading

0 comments on commit 925f3c0

Please sign in to comment.