From 510a9df9ffe54662b5b839be391f733ce7b6e677 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 25 Feb 2024 00:59:50 +0000 Subject: [PATCH 1/2] Zend/tests/offsets: add tests for taking references --- ...rrayAccess_container_offset_behaviour.phpt | 19 +- ...rrayObject_container_offset_behaviour.phpt | 122 +++++---- .../array_container_offset_behaviour.phpt | 111 ++++---- .../false_container_offset_behaviour.phpt | 115 +++++---- .../invalid_container_offset_behaviour.phpt | 6 +- .../null_container_offset_behaviour.phpt | 111 ++++---- .../object_container_offset_behaviour.phpt | 2 + .../reference_containers_appended.phpt | 76 ++++++ .../string_container_offset_behaviour.phpt | 238 ++++++++++-------- Zend/tests/offsets/test_variable_offsets.inc | 12 + 10 files changed, 528 insertions(+), 284 deletions(-) create mode 100644 Zend/tests/offsets/reference_containers_appended.phpt diff --git a/Zend/tests/offsets/ArrayAccess_container_offset_behaviour.phpt b/Zend/tests/offsets/ArrayAccess_container_offset_behaviour.phpt index 189dc0c1a2e6..5a5fab352be3 100644 --- a/Zend/tests/offsets/ArrayAccess_container_offset_behaviour.phpt +++ b/Zend/tests/offsets/ArrayAccess_container_offset_behaviour.phpt @@ -40,6 +40,17 @@ VAR_DUMP_OF_OFFSET string(12) "CLASS_NAME::offsetGet" VAR_DUMP_OF_OFFSET int(5) +Reference to dimension: +string(12) "CLASS_NAME::offsetGet" +VAR_DUMP_OF_OFFSET + +Notice: Indirect modification of overloaded element of CLASS_NAME has no effect in %s on line 55 +Value of reference: +int(5) +Value of container dimension after write to reference (should be int(100) if successful): +string(12) "CLASS_NAME::offsetGet" +VAR_DUMP_OF_OFFSET +int(5) unset(): string(14) "CLASS_NAME::offsetUnset" VAR_DUMP_OF_OFFSET @@ -47,19 +58,19 @@ Nested read: string(12) "CLASS_NAME::offsetGet" VAR_DUMP_OF_OFFSET -Warning: Trying to access array offset on int in %s on line 62 +Warning: Trying to access array offset on int in %s on line 74 NULL Nested write: string(12) "CLASS_NAME::offsetGet" VAR_DUMP_OF_OFFSET -Notice: Indirect modification of overloaded element of CLASS_NAME has no effect in %s on line 69 +Notice: Indirect modification of overloaded element of CLASS_NAME has no effect in %s on line 81 Cannot use a scalar value as an array Nested Read-Write: string(12) "CLASS_NAME::offsetGet" VAR_DUMP_OF_OFFSET -Notice: Indirect modification of overloaded element of CLASS_NAME has no effect in %s on line 76 +Notice: Indirect modification of overloaded element of CLASS_NAME has no effect in %s on line 88 Cannot use a scalar value as an array Nested isset(): string(15) "CLASS_NAME::offsetExists" @@ -83,7 +94,7 @@ Nested unset(): string(12) "CLASS_NAME::offsetGet" VAR_DUMP_OF_OFFSET -Notice: Indirect modification of overloaded element of CLASS_NAME has no effect in %s on line 102 +Notice: Indirect modification of overloaded element of CLASS_NAME has no effect in %s on line 114 Cannot unset offset in a non-array variable OUTPUT; diff --git a/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt b/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt index 2e43d57d1840..ae4685f093ee 100644 --- a/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt +++ b/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt @@ -8,7 +8,7 @@ require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc'; const EXPECTED_OUTPUT_VALID_OFFSETS = <<getMessage(), "\n"; + } +} + +?> +--EXPECTF-- +NULL container: +array(1) { + [0]=> + &NULL +} +NULL +false container: + +Deprecated: Automatic conversion of false to array is deprecated in %s on line %d +array(1) { + [0]=> + &NULL +} +NULL +true container: +Error: Cannot use a scalar value as an array +4 container: +Error: Cannot use a scalar value as an array +5.5 container: +Error: Cannot use a scalar value as an array +'10' container: +Error: [] operator not supported for strings +'25.5' container: +Error: [] operator not supported for strings +'string' container: +Error: [] operator not supported for strings +[] container: +array(1) { + [0]=> + &NULL +} +NULL +STDERR container: +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 +object(ArrayObject)#2 (1) { + ["storage":"ArrayObject":private]=> + array(0) { + } +} +NULL +new A() container: +string(12) "A::offsetGet" +NULL + +Notice: Indirect modification of overloaded element of A has no effect in %s on line %d +object(A)#3 (0) { +} +int(5) +new B() container: + +Notice: Indirect modification of overloaded element of B has no effect in %s on line %d +ArgumentCountError: B::offsetGet(): Argument #1 ($offset) not passed diff --git a/Zend/tests/offsets/string_container_offset_behaviour.phpt b/Zend/tests/offsets/string_container_offset_behaviour.phpt index 695008c5dbc2..55427957f7af 100644 --- a/Zend/tests/offsets/string_container_offset_behaviour.phpt +++ b/Zend/tests/offsets/string_container_offset_behaviour.phpt @@ -8,7 +8,7 @@ require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc'; const EXPECTED_OUTPUT_VALID_OFFSETS = <<getMessage(), "\n"; } +// Fetch reference +try { + echo "Reference to dimension:\n"; + $r = &$container[$dimension]; + echo "Value of reference:\n"; + var_dump($r); + $r = 100; + echo "Value of container dimension after write to reference (should be int(100) if successful):\n"; + var_dump($container[$dimension]); +} catch (\Throwable $e) { + echo $e->getMessage(), "\n"; +} // Unset try { echo "unset():\n"; From c677c737afaba43806661aa4956b9daa8087641e Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 25 Feb 2024 01:32:38 +0000 Subject: [PATCH 2/2] Add extre fetch append test for internal handlers --- Zend/tests/offsets/internal_handlers.phpt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Zend/tests/offsets/internal_handlers.phpt b/Zend/tests/offsets/internal_handlers.phpt index ed581ef38f05..a75e706ab8af 100644 --- a/Zend/tests/offsets/internal_handlers.phpt +++ b/Zend/tests/offsets/internal_handlers.phpt @@ -209,6 +209,15 @@ try { } exportObject($o); +echo 'reference fetch-append', PHP_EOL; +$o = new DimensionHandlersNoArrayAccess(); +try { + $r = &$o[]; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +exportObject($o); + ?> --EXPECTF-- read op @@ -281,3 +290,7 @@ nested reference fetching Notice: Indirect modification of overloaded element of DimensionHandlersNoArrayAccess has no effect in %s on line %d Error: Cannot use a scalar value as an array DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_W, hasOffset: true, checkEmpty: uninitialized, offset: 'foo' +reference fetch-append + +Notice: Indirect modification of overloaded element of DimensionHandlersNoArrayAccess has no effect in %s on line %d +DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_W, hasOffset: false, checkEmpty: uninitialized, offset: uninitialized