Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Improve language coherence for the behaviour of offsets and containers: object handlers #14920

Draft
wants to merge 58 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
7fed0cf
Zend/zend_execute.c: use zend_check_string_offset() for all string of…
Girgias Jan 25, 2024
3043fdd
Zend: Move dimension handlers from object handlers to CE
Girgias Jan 31, 2024
fba8aac
Add assertion and debug check function that interfaces are implemented
Girgias Feb 19, 2024
7a5d0d6
Disable debug
Girgias Feb 20, 2024
400aeb9
Deref offset in VM
Girgias May 28, 2024
dc132a8
ext/simplexml: Convert SimpleXML to new dimension API
Girgias May 28, 2024
8c0679b
ext/dom: Convert DOM classes to new dimension API
Girgias May 28, 2024
18ffb74
ext/intl: Convert ResourceBundle to new dimension API
Girgias Feb 27, 2024
b185ba3
ext/pdo: Convert PDORow to new dimension API
Girgias Feb 27, 2024
95c673f
ext/spl: Convert SplFixedArray to new API
Girgias Feb 27, 2024
a130940
VM call offsetGet when offsetExists returns true
Girgias May 28, 2024
bec7da9
Zend: Convert WeakMap to new dimension API
Girgias May 28, 2024
2739d87
ext/spl: Convert SplObjectStorage to new API
Girgias May 30, 2024
b1902fe
ext/spl: Clean-up SplObjectStorage implementation
Girgias May 30, 2024
afda402
Use static struct for SplObjectStorage dimension handlers
Girgias Jun 8, 2024
bca99ca
ext/spl: [WIP] Convert ArrayObject to new API
Girgias May 31, 2024
d5a9403
ext/ffi: Convert CData to new API
Girgias Feb 21, 2024
676e7c6
Use static struct for function handlers in zend_test
Girgias Jun 8, 2024
9f2cdb7
Use static structs for internal classes
Girgias Jun 8, 2024
e6aa79b
ext/phar: expand test to cover issue with offsetGet
Girgias Jun 7, 2024
6a2cc14
ext/phar: offsetExists should return false when file entry is not bas…
Girgias Jun 7, 2024
0b9f374
Fix append binary op
Girgias Jun 10, 2024
b3f4996
Fix issue when returning object by-ref in fetch
Girgias Jun 10, 2024
01ab9ad
Clean-up implementation of zend_legacy_ArrayAccess_fetch_dimension
Girgias Jun 10, 2024
731cf45
Fix by ref assignments for ArrayObject only
Girgias Jun 10, 2024
864304b
Support indirect, add tests for objects with binary op
Girgias Jun 11, 2024
a619bf3
Fix ArrayAccess for good
Girgias Jun 11, 2024
5c4846a
Fix indirect modification of offset when handler uses global
Girgias Jul 1, 2024
044486d
Improve debug assertion now that conversion is mostly done
Girgias Jul 1, 2024
2b7905c
JIT Support
Girgias Jul 2, 2024
8bb48e0
Do we even need to create a ref?
Girgias Jul 2, 2024
f516c9a
Add missing GMP extension
Girgias Jul 3, 2024
36e2645
ArrayObject arginfos
Girgias Jul 3, 2024
56f60ca
Define default ArrayAccess handlers for internal classes
Girgias Jul 3, 2024
c5e2e05
ext/com: Convert to new API [W.I.P.]
Girgias Jul 3, 2024
d3a5e9d
Remove old dimension handlers
Girgias Jul 3, 2024
c085db5
Fix persistence code in opcache
Girgias Jul 9, 2024
7fcff94
opcache file persistence W.I.P.
Girgias Jul 9, 2024
ed45d0d
Remove unused zend_class_arrayaccess_funcs struct now
Girgias Jul 9, 2024
b40fb05
Have ArrayAccess extend the relevant interfaces
Girgias Jul 11, 2024
c2defa7
Prevent DimensionReadable::offsetGet() to be implemented returning by…
Girgias Jul 11, 2024
a761cee
Add all containers in helper
Girgias Jul 11, 2024
2ab890f
Add test for isset/empty behaviour with all container types
Girgias Jul 11, 2024
c2d76b9
Add tests for increment/decrement on a container offset
Girgias Jul 11, 2024
793db06
Emit warning for RW fetch if offset does not exist
Girgias Jul 12, 2024
898de1e
Error when trying to increment/decrement object offsets
Girgias Jul 13, 2024
5caab8d
Prototype for auto-vivification
Girgias Jul 13, 2024
1157238
Simply increment/decrement check
Girgias Jul 16, 2024
cde9950
Simplify auto-vivification check
Girgias Jul 16, 2024
11e07f9
Use a union to cache zend_function*
Girgias Jul 16, 2024
10f31bc
Test fixes for increment/decrement change
Girgias Jul 16, 2024
3c33e2d
Autovivify via a handler
Girgias Jul 16, 2024
2aea394
Update autovivification change in a test
Girgias Jul 16, 2024
bc5da36
Revert "Update autovivification change in a test"
Girgias Jul 16, 2024
bd77eee
Bodge JIT support again
Girgias Jul 18, 2024
080a2be
Fix property hook test
Girgias Jul 18, 2024
3a53217
Fix opcache pointer serialization after change
Girgias Jul 18, 2024
8e5d564
Fix opline
Girgias Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Zend/tests/bug31683.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
NULL
string(2) "ok"
string(2) "ok"
Expand All @@ -90,6 +91,7 @@ string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
string(2) "ok"
NULL
string(2) "ok"
string(2) "ok"
Expand Down
4 changes: 4 additions & 0 deletions Zend/tests/bug63217.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,19 @@ var_dump($ao);
?>
--EXPECT--
offsetExists given string(1) "0"
offsetGet given string(1) "0"
offsetExists given string(3) "123"
offsetGet given string(3) "123"
offsetUnset given string(1) "0"
offsetUnset given string(3) "123"
offsetSet given string(1) "0"
offsetSet given string(3) "123"
offsetGet given string(1) "0"
offsetGet given string(3) "123"
offsetExists given string(1) "0"
offsetGet given string(1) "0"
offsetExists given string(3) "123"
offsetGet given string(3) "123"
offsetUnset given string(1) "0"
offsetUnset given string(3) "123"
offsetSet given string(1) "0"
Expand Down
3 changes: 2 additions & 1 deletion Zend/tests/bug64417.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class obj implements ArrayAccess {

$o = new obj;
$o['x'] = 1;
++$o['x'];
$ref = &$o['x'];
$ref++;
echo $o['x'], "\n";
?>
--EXPECT--
Expand Down
4 changes: 3 additions & 1 deletion Zend/tests/bug69955.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ $c10 = new C10;

var_dump($c10[] += 5);
?>
--EXPECT--
--EXPECTF--
Inside C10::offsetGet
NULL

Notice: Indirect modification of overloaded element of C10 has no effect in %s on line %d

Inside C10::offsetSet
NULL
int(105)
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug75420.10.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ var_dump($obj[$name] ?? 12);
var_dump($name);
?>
--EXPECT--
string(6) "foofoo"
int(24)
int(42)
int(24)
2 changes: 1 addition & 1 deletion Zend/tests/bug75420.11.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ var_dump(empty($obj[$name]));
var_dump($name);
?>
--EXPECT--
string(3) "foo"
int(24)
bool(false)
int(24)
2 changes: 1 addition & 1 deletion Zend/tests/bug75420.12.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ var_dump(empty($obj[$name]));
var_dump($name);
?>
--EXPECT--
string(6) "foofoo"
int(24)
bool(false)
int(24)
20 changes: 20 additions & 0 deletions Zend/tests/bug75420.17.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Bug #75420.17 (Indirect modification of magic method argument)
--FILE--
<?php
class Test implements ArrayAccess {
public function offsetExists($x): bool { $GLOBALS["obj"] = 24; return true; }
public function offsetGet($x): mixed { var_dump($x); return 42; }
public function offsetSet($x, $y): void { }
public function offsetUnset($x): void { }
}

$obj = new Test;
$name = "foo";
var_dump(isset($obj[$name]));
var_dump($obj);
?>
--EXPECT--
string(3) "foo"
bool(true)
int(24)
2 changes: 1 addition & 1 deletion Zend/tests/bug75420.9.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ var_dump($obj[$name] ?? 12);
var_dump($name);
?>
--EXPECT--
string(3) "foo"
int(24)
int(42)
int(24)
4 changes: 2 additions & 2 deletions Zend/tests/in-de-crement/overloaded_access.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ try {
}
?>
--EXPECT--
Cannot increment array
Cannot decrement array
Cannot increment/decrement object offsets
Cannot increment/decrement object offsets
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,8 @@ offsetGet
offsetGet
offsetGet
offsetExists
offsetGet
offsetExists
offsetGet
offsetExists
offsetGet
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ int(25)
isset():
string(15) "CLASS_NAME::offsetExists"
VAR_DUMP_OF_OFFSET
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET
bool(true)
empty():
string(15) "CLASS_NAME::offsetExists"
Expand Down Expand Up @@ -67,6 +69,8 @@ VAR_DUMP_OF_OFFSET
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(15) "CLASS_NAME::offsetExists"
VAR_DUMP_OF_OFFSET
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET

Expand Down Expand Up @@ -100,7 +104,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
90 changes: 36 additions & 54 deletions Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ bool(false)
Nested null coalesce:
int(30)
Nested unset():

OUTPUT;

$EXPECTED_OUTPUT_VALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_VALID_OFFSETS) . '$/s';
Expand All @@ -58,27 +59,33 @@ Deprecated: Implicit conversion from float %F to int loses precision in %s on li
Read:

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
int(15)
int(5)
Read-Write:

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
isset():

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
bool(true)
empty():

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
bool(false)
null coalesce:

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
int(35)

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
int(25)
Reference to dimension:

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
Value of reference:
int(35)
int(25)
Value of container dimension after write to reference (should be int(100) if successful):

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
Expand All @@ -90,9 +97,9 @@ Nested read:

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d

Warning: Undefined array key 0 in %s on line %d
Warning: Undefined array key %s in %s on line %d

Warning: Trying to access array offset on null in %s on line %d
Warning: Trying to access array offset on null in %s on line 74
NULL
Nested write:

Expand All @@ -103,25 +110,33 @@ Nested Read-Write:

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
Nested isset():

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
bool(true)
Nested empty():

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
bool(false)
Nested null coalesce:

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
int(25)

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
int(30)
Nested unset():

Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
Expand Down Expand Up @@ -164,57 +179,12 @@ Cannot access offset of type %s in isset or empty
Nested null coalesce:
Cannot access offset of type %s in isset or empty
Nested unset():

Notice: Indirect modification of overloaded element of ArrayObject has no effect in %s on line %d
Cannot unset offset of type %s on ArrayObject
Cannot access offset of type %s on ArrayObject

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 All @@ -236,14 +206,20 @@ Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 29
Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 29
isset():

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 36

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 36
bool(true)
empty():

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 42

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 42
bool(false)
null coalesce:

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 48

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 48
int(25)
Reference to dimension:
Expand Down Expand Up @@ -275,23 +251,31 @@ Nested Read-Write:

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 88

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 88

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 88
Nested isset():

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95
bool(true)
Nested empty():

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 101

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 101

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 101
bool(false)
Nested null coalesce:

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 107

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 107

Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 107
int(30)
Nested unset():
Expand Down Expand Up @@ -323,7 +307,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 @@ -354,7 +337,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
Loading
Loading