Commit Graph

18853 Commits

Author SHA1 Message Date
Ilija Tovilo
af3d2f7ec9
Fix double-free of doc_comment when overriding static property via trait
When redeclaring an overridden static property with a trait we're removing the
property from the class. However, because the property itself does not belong to
the class we must not free its associated data.

This issue is exposed by 9a250cc9d6 in PHP 8.3+ because duplicate static
properties in traits are no longer skipped, but redeclared.

Fixes GH-12468
2023-10-19 15:21:53 +02:00
Niels Dossche
cdfa016854
Avoid refcounted copy in _object_properties_init() for internal classes (#12474)
This currently uses ZVAL_COPY_OR_DUP, which copies the value and handles
refcounting. However, internal classes cannot have refcounted default
properties because of constraints imposed by
zend_declare_typed_property(). So copying the value is sufficient.

While this doesn't really improve the performance for our benchmarks, it
improves performance for cases where a lot of temporary internal objects
are instantiated. For example, when instantiating DOM classes: DOM
objects are transient, so lots of temporary objects are created.
2023-10-19 12:34:55 +02:00
Ilija Tovilo
94c1e559f9
Merge branch 'PHP-8.3'
* PHP-8.3:
  Implement diagnostic ignore macro for Clang
2023-10-18 17:38:12 +02:00
Ilija Tovilo
80b4c73030
Implement diagnostic ignore macro for Clang
Newer versions of Clang now also complain about -Wscript-prototypes for included
headers.

Closes GH-12467
2023-10-18 17:37:15 +02:00
Ilija Tovilo
f39b5c4c25
Close PHP tags in tests
Closes GH-12422
2023-10-18 17:34:10 +02:00
Ilija Tovilo
25f42bc9ce
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fixed a bug in zend_memnistr with single character needle
2023-10-18 16:02:27 +02:00
Ilija Tovilo
0de79a8f5a
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fixed a bug in zend_memnistr with single character needle
2023-10-18 16:02:19 +02:00
SakiTakamachi
736032febf
Fixed a bug in zend_memnistr with single character needle
Fixes GH-12457
Closes GH-12458
2023-10-18 16:00:49 +02:00
Jakub Zelenka
14404ac1fa
Merge branch 'PHP-8.3' 2023-10-14 18:45:31 +01:00
Jakub Zelenka
2913447653
Merge branch 'PHP-8.2' into PHP-8.3 2023-10-14 18:44:26 +01:00
Jakub Zelenka
c776f79578
Merge branch 'PHP-8.1' into PHP-8.2 2023-10-14 18:41:48 +01:00
Jakub Zelenka
0217be4d5b
Fix GH-12232: FPM: segfault dynamically loading extension without opcache
Also fixes incorrect assertion in ini init that php_dl is always
temporary.

Closes GH-12277
2023-10-14 18:38:21 +01:00
Niels Dossche
345ac90eac
Introduce Z_PARAM_FUNC_EX2 to maintain compatibility (#12419)
Commit d86314939c added an additional parameter to Z_PARAM_FUNC_EX.
To maintain compatibility with third-party extensions, we keep
Z_PARAM_FUNC_EX as it used to be, and add Z_PARAM_FUNC_EX2 instead.
2023-10-11 19:55:00 +02:00
Niels Dossche
0ba24a5ed9 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-12392: Segmentation fault on SoapClient::__getTypes
  Fix GH-11121: ReflectionFiber segfault
  [ci skip] NEWS
2023-10-11 17:32:22 +02:00
Niels Dossche
124c812542 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-12392: Segmentation fault on SoapClient::__getTypes
  Fix GH-11121: ReflectionFiber segfault
  [ci skip] NEWS
2023-10-11 17:27:54 +02:00
Niels Dossche
d8cd0f4ba0 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-12392: Segmentation fault on SoapClient::__getTypes
  Fix GH-11121: ReflectionFiber segfault
  [ci skip] NEWS
2023-10-11 17:23:17 +02:00
Daniil Gentili
71f14510f6 Fix GH-11121: ReflectionFiber segfault
Closes GH-12391.

Co-authored-by: Aaron Piotrowski <aaron@trowski.com>
2023-10-11 17:19:01 +02:00
Ilija Tovilo
fc4f0ff377
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix use-after-free of constant name
2023-10-11 11:52:21 +02:00
Ilija Tovilo
2e6d34c72e
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix use-after-free of constant name
2023-10-11 11:52:11 +02:00
Ilija Tovilo
53dbb760da
Fix use-after-free of constant name
The constant name is usually interend. Without opcache, compilation always
interns strings. Without opcache, compilation does not intern (new) strings, but
persisting of script does. If a script is not stored in shm the constant name
will not be interned.

The building of enum backing stores was missing a addref for the constant name,
leading to a double-free when releasing constants and backing stores of enums.

Fixes GH-12366
Closes GH-12405
2023-10-11 11:49:40 +02:00
Patrick Allaert
be64db5939
PHP-8.1 is now for PHP 8.1.26-dev 2023-10-10 22:54:03 +02:00
Pierrick Charron
2642a08697
PHP-8.2 is now for PHP 8.2.13-dev 2023-10-10 11:45:26 -04:00
George Peter Banyard
d86314939c Zend: Add ZPP F type check for callables that do not free trampolines
As refetching it with the new FCC API does get tedious
2023-10-10 13:44:21 +01:00
George Peter Banyard
76a773b8dd
Add some const qualifiers in HashTable foreach macros (#8671) 2023-10-09 17:20:09 +01:00
Ilija Tovilo
24d6dce668
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix invalid returned opcode for memoized expressions
2023-10-03 14:02:28 +02:00
Ilija Tovilo
4ba5699903
Fix invalid returned opcode for memoized expressions
Closes GH-12345
2023-10-03 14:01:43 +02:00
Dmitry Stogov
a01e0aa590 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fixed GH-12262: Tracing JIT assertion crash when using phpstan
2023-10-03 13:25:46 +03:00
Dmitry Stogov
9bfdb4cf4b Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fixed GH-12262: Tracing JIT assertion crash when using phpstan
2023-10-03 13:25:36 +03:00
Dmitry Stogov
101bd1b199 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed GH-12262: Tracing JIT assertion crash when using phpstan
2023-10-03 13:25:22 +03:00
Dmitry Stogov
54452b4811 Fixed GH-12262: Tracing JIT assertion crash when using phpstan 2023-10-03 13:22:33 +03:00
David CARLIER
3944bb01eb
zend call stack for DragonFlyBSD. (#12325)
Shares the same codepaths as FreeBSD for the most part.
2023-10-01 13:12:14 +01:00
Niels Dossche
2fb9ef069f Merge branch 'PHP-8.3'
* PHP-8.3:
  Revert "Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT"
2023-09-30 01:27:43 +02:00
Niels Dossche
04a2a42f2a Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Revert "Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT"
2023-09-30 01:27:29 +02:00
Niels Dossche
0f5b382528 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Revert "Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT"
2023-09-30 01:27:06 +02:00
Niels Dossche
643c4ba417 Revert "Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT"
Although it passes CI on 8.1, it causes CI failures in the JIT on 8.2 and
higher.
See https://github.com/php/php-src/actions/runs/6357716718/job/17269225001

This reverts commit e72fc12058.
2023-09-30 01:25:48 +02:00
Niels Dossche
5fd89652e5 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix compile error with -Werror=incompatible-function-pointer-types and old libxml2
  Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
  Fix type error on XSLTProcessor::transformToDoc return value with SimpleXML
2023-09-30 00:12:42 +02:00
Niels Dossche
fa2d556fcd Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
  Fix type error on XSLTProcessor::transformToDoc return value with SimpleXML
2023-09-30 00:11:31 +02:00
Niels Dossche
d7a7309b53 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
  Fix type error on XSLTProcessor::transformToDoc return value with SimpleXML
2023-09-30 00:10:35 +02:00
Niels Dossche
e72fc12058 Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
This test triggers narrowing for two ops: first ZEND_ADD_ARRAY_ELEMENT,
and then ZEND_ASSIGN.

The type inference happens in the following order:
1) The ZEND_ADD_ARRAY_ELEMENT infers type 0x40e04080 (packed flag is set),
   arr_type=0 at this point because it hasn't been set by ZEND_INIT_ARRAY yet.
2) The ZEND_INIT_ARRAY infers type 0x40804080
3) The ZEND_ADD_ARRAY_ELEMENT infers type 0x40e04080, arr_type=0x40804080,
   which does not have the packed flag set while the existing result of
   ZEND_ADD_ARRAY_ELEMENT has the packed flag set.

This seems to occur because of the phi node introduced by the while
loop. If I remove the loop the problem goes away.

As Arnaud noted, this seems to be caused by a too wide type inference
for arr_type==0. We should keep the invariant that if x>=y then
key_type(x) >= key_type(y).
If we write the possible results down in a table we get:

```
arr_type           resulting key type
---------------    --------------------------------------------------------------------------
HASH_ONLY	-> MAY_BE_ARRAY_NUMERIC_HASH
PACKED_ONLY	-> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
HASH || PACKED	-> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
0		-> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
```

As we can see, `HASH_ONLY > 0` but
`MAY_BE_ARRAY_NUMERIC_HASH < MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED`,
which violates the invariant.
Instead if we modify the zero case to have MAY_BE_ARRAY_NUMERIC_HASH instead,
we get the following table which satisfies the invariant.

```
arr_type           resulting key type
---------------    --------------------------------------------------------------------------
HASH_ONLY	-> MAY_BE_ARRAY_NUMERIC_HASH
PACKED_ONLY	-> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
HASH || PACKED	-> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
0		-> MAY_BE_ARRAY_NUMERIC_HASH
```

Broke in 1ffbb73.
Closes GH-10294.
2023-09-30 00:08:32 +02:00
David CARLIER
14b827049a
zend call stack support for haiku w/o using posix pthread api but the (#12103)
underlying native BeOs one.
2023-09-29 11:47:23 +01:00
Niels Dossche
9b6afd88fb
Make sure core module has number 0 (#12272)
* Make sure core module has number 0

Some places, possibly also outside PHP, assume the core extension has
module number 0. After 8a812c3fda this wasn't the case anymore as
reported in [1]. Fix it by changing how the next module ID is computed.

[1] https://github.com/php/php-src/pull/12246#issuecomment-1731432377

* Add assertion

* Add test
2023-09-25 17:36:13 +02:00
Levi Morrison
f1f04cf0c9
Merge branch 'PHP-8.3' 2023-09-25 08:27:46 -06:00
Levi Morrison
8fb51d4fe4
Set func pointer to null in Closure __invoke (#12275) 2023-09-25 08:27:23 -06:00
Ilija Tovilo
62e2402534
Use autoconf for recognizing __builtin_unreachable() (#12266)
Older versions of GCC don't support __has_builtin(), but do support
__builtin_unreachable().
2023-09-22 11:53:09 +02:00
Niels Dossche
8a812c3fda Fix GH-12215: Module entry being overwritten causes type errors in ext/dom (PHP 8.4)
When we try to load an extension multiple times, we still overwrite the
type, module number, and handle. If the module number is used to
indicate module boundaries (e.g. in reflection and in dom, see e.g.
dom_objects_set_class_ex), then all sorts of errors can happen.

In the case of ext/dom, OP's error happens because the following
happens:
- The property handler is set up incorrectly in
  dom_objects_set_class_ex() because the wrong module number is
  specified. The class highest in the hierarchy is DOMNode, so the
  property handler is incorrectly set to that of DOMNode instead of
  DOMDocument.
- The documentElement property doesn't exist on DOMNode, it only exists
  on DOMDocument, so it tries to read using zend_std_read_property().
  As there is no user property called documentElement, that read
  operation returns an undef value.
  However, the type is still checked, resulting in the strange exception.

Solve this by changing the API such that the data is only overwritten if
it's owned data.

Closes GH-12246.
2023-09-20 21:02:51 +02:00
Ilija Tovilo
37ce7199f2
Use __builtin_unreachable() directly in ZEND_UNREACHABLE
ZEND_UNREACHABLE() currently expands to the following in GCC:

    if (__builtin_expect(!(0), 0)) __builtin_unreachable();

Even though the branch is always executed, GCC does not recognize the outer
branch as unreachable. Removing the if fixes some unexpected warnings.

Closes GH-12248
2023-09-20 15:44:02 +02:00
Ilija Tovilo
f957335c66
Move static property check to assert (#12239)
Staticness incompatiblity must error before attempting to declare the property.
2023-09-19 10:35:25 +02:00
David Carlier
f78c8b91eb Merge branch 'PHP-8.3' 2023-09-18 17:47:44 +01:00
David Carlier
639bcb4078 Merge branch 'PHP-8.2' into PHP-8.3 2023-09-18 17:46:28 +01:00
David Carlier
c39d4481c5 Merge branch 'PHP-8.1' into PHP-8.2 2023-09-18 17:46:11 +01:00
Florian Sowade
910f579f14 Fix GH-12207 memory leak of doc blocks of static properties
When declaring the same static property with a doc block in a class and in a trait,
the doc block of the property in the class is leaked. While at it, possibly fix doc
 comment for internal classes.

Close GH-12238
2023-09-18 17:44:47 +01:00
George Peter Banyard
42010d42f1
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fixed oss-fuzz #62294: Unsetting variable after ++/-- on string variable warning
2023-09-17 15:50:54 +01:00
George Peter Banyard
0b614a6c2b
Fixed oss-fuzz #62294: Unsetting variable after ++/-- on string variable warning
Closes GH-12202
2023-09-17 15:49:46 +01:00
Tim Düsterhus
7c4db150cb
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix #[Override] on traits overriding a parent method without a matching interface (#12205)
2023-09-15 14:57:42 +02:00
Tim Düsterhus
d344fe06a2
Fix #[Override] on traits overriding a parent method without a matching interface (#12205)
Fixes GH-12189

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2023-09-15 14:57:10 +02:00
Tim Düsterhus
ede180672b
Merge branch 'PHP-8.3'
* PHP-8.3:
  Add abstract __construct() test for #[\Override] (024.phpt)
2023-09-14 12:58:31 +02:00
Tim Düsterhus
0e9d658dd2
Add abstract __construct() test for #[\Override] (024.phpt) 2023-09-14 12:58:08 +02:00
Ilija Tovilo
692cea5cbc
Use zend_error_noreturn for E_ERROR consistently
To be clear, these already don't return. zend_error_noreturn just hints at this
fact through the ZEND_NORETURN attribute.

Closes GH-12204
2023-09-14 11:44:55 +02:00
Ilija Tovilo
2227fefa17
Fix noreturn with warning that should be an error
E_WARNING does not actually abort.
2023-09-14 11:29:53 +02:00
Ben Ramsey
c1cf0026e5
PHP-8.1 is now for PHP 8.1.25-dev 2023-09-12 16:21:51 -05:00
Sergey Panteleev
5c1f746716
PHP-8.2 is now for PHP 8.2.12-dev 2023-09-12 14:53:56 +03:00
Ilija Tovilo
02d3eecf8d
Merge branch 'PHP-8.3'
* PHP-8.3:
  Improve invalid cpp modifier message
2023-09-11 16:24:16 +02:00
Ilija Tovilo
011071a3b3
Improve invalid cpp modifier message
The ZEND_MODIFIER_TARGET_CPP should really have been called _PARAM, but we
shouldn't break API at this point.

Fixes GH-12069
Closes GH-12175
2023-09-11 16:23:43 +02:00
George Peter Banyard
5c3a6eaec9
Zend: Remove dependency on zend.h for certain headers (#12166) 2023-09-11 12:27:21 +01:00
Ilija Tovilo
4217d55022
Merge branch 'PHP-8.3'
* PHP-8.3:
  [skip ci] Skip arginfo_zpp_mismatch on asan
2023-09-11 11:36:30 +02:00
Ilija Tovilo
214afe0d96
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [skip ci] Skip arginfo_zpp_mismatch on asan
2023-09-11 11:36:22 +02:00
Ilija Tovilo
1c93cdcea4
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [skip ci] Skip arginfo_zpp_mismatch on asan
2023-09-11 11:35:51 +02:00
Ilija Tovilo
5286bab392
[skip ci] Skip arginfo_zpp_mismatch on asan
These tests intermittently crash asan. It might be due to some function invoking
dl(), which is known to crash lsan. It might also be something else, the version
of asan shipped with ubuntu 22.04 is flaky.
2023-09-11 11:32:34 +02:00
Máté Kocsis
038e9b7e4b
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix #12123 Make _ZEND_TYPE_PREFIX apply only for MSVC
2023-09-10 22:43:00 +02:00
Máté Kocsis
45c7e3b06b
Fix #12123 Make _ZEND_TYPE_PREFIX apply only for MSVC
Closes GH-12136
2023-09-10 22:40:50 +02:00
David Carlier
aef5225394 zend_call_stack_get implementation for NetBSD.
Despite being OpenBSD's predecessor, the approach is in fact
a lot closer to Linux, at least in principle. We purposely
avoid reading /proc/N/maps to be more future-proof.

Close GH-11637
2023-09-09 13:48:40 +01:00
Ilija Tovilo
c803402162
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix zend_separate_if_call_and_write for FUNC_ARGs
2023-09-07 14:26:31 +02:00
Ilija Tovilo
c2bb9bc0df
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix zend_separate_if_call_and_write for FUNC_ARGs
2023-09-07 14:26:09 +02:00
Ilija Tovilo
fa9cef8b47
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix zend_separate_if_call_and_write for FUNC_ARGs
2023-09-07 14:25:43 +02:00
Ilija Tovilo
748adf18fc
Fix zend_separate_if_call_and_write for FUNC_ARGs
Fixes GH-12102
Closees GH-12140
2023-09-07 14:25:11 +02:00
Máté Kocsis
2cb4d00693
Improve detection of predefined constants
In order to include constants documented at https://www.php.net/manual/en/reserved.constants.php, as well as constants which share the same varlistentry (just like what
https://www.php.net/manual/en/class.datetimeinterface.php#datetimeinterface.constants.atom does). In the same time, special constants like
true, false, null are excluded, since the manual uses their entity (&true;, &false, &null;, respectively), and gen_stub.php couldn't detect
them.
2023-09-07 10:00:55 +02:00
George Peter Banyard
2d3bff38bb Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
2023-09-05 10:41:22 +01:00
George Peter Banyard
8a392eddf9 Fix OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
Reorder when we assign the property value to NULL which is identical to
a3a3964497

Just for the declared property case instead of dynamic.

Closes GH-12114
2023-09-05 10:40:02 +01:00
George Peter Banyard
ee6453f737 Merge branch 'PHP-8.3'
* PHP-8.3:
  Prevents double call to internal iterator rewind handler
  adds failing test case for #12060
2023-09-05 10:37:00 +01:00
George Peter Banyard
d7273c5963 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Prevents double call to internal iterator rewind handler
  adds failing test case for #12060
2023-09-05 10:36:16 +01:00
George Peter Banyard
c672a06954 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Prevents double call to internal iterator rewind handler
  adds failing test case for #12060
2023-09-05 10:27:33 +01:00
ju1ius
da7a66d647 Prevents double call to internal iterator rewind handler
Closes GH-12060

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-09-05 10:26:19 +01:00
Dmitry Stogov
8cfe2674e3 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fixed uninitialized EX(opline) access (possible Zend/tests/gh12073.phpt crash)
2023-09-05 10:13:55 +03:00
Dmitry Stogov
b4ce171aa2 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fixed uninitialized EX(opline) access (possible Zend/tests/gh12073.phpt crash)
2023-09-05 10:13:47 +03:00
Dmitry Stogov
ab6d564a7e Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed uninitialized EX(opline) access (possible Zend/tests/gh12073.phpt crash)
2023-09-05 10:13:22 +03:00
Dmitry Stogov
f1f608bf53 Fixed uninitialized EX(opline) access (possible Zend/tests/gh12073.phpt crash) 2023-09-05 10:11:54 +03:00
Ilija Tovilo
3f38105740
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix freeing of incompletely initialized closures
2023-09-04 15:40:07 +02:00
Ilija Tovilo
baf74ed1a4
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix freeing of incompletely initialized closures
2023-09-04 15:39:39 +02:00
Ilija Tovilo
6850a040f3
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix freeing of incompletely initialized closures
2023-09-04 15:39:20 +02:00
Ilija Tovilo
af2110e664
Fix freeing of incompletely initialized closures
Addref to relevant fields before allocating any memory. Also only set/remove the
ZEND_ACC_HEAP_RT_CACHE flag after allocating memory.

Fixes GH-12073
Closes GH-12074
2023-09-04 15:35:39 +02:00
Niels Dossche
e2189e5f37 Merge branch 'PHP-8.3'
* PHP-8.3:
  Tweak behaviour of dynamic properties wrt error handlers
2023-09-03 18:27:32 +02:00
Niels Dossche
eee1617f38 Tweak behaviour of dynamic properties wrt error handlers
With the fix in https://github.com/php/php-src/pull/12114, the behaviour
would change for non-dynamic properties. Align the behaviour for dynamic
properties to be the same.

Closes GH-12117.
2023-09-03 18:27:21 +02:00
George Peter Banyard
575263ff3f Merge branch 'PHP-8.3'
* PHP-8.3:
  Add tests for oss-fuzz-61469: Undef dynamic property in ++/-- unset in error handler
2023-09-02 23:35:16 +01:00
George Peter Banyard
013bb5769b Add tests for oss-fuzz-61469: Undef dynamic property in ++/-- unset in error handler
This was fixed as a consequence of a3a3964497

Closes GH-12011
2023-09-02 23:34:20 +01:00
Remi Collet
2521a3fce1
Merge branch 'PHP-8.3'
* PHP-8.3:
  ensure displays_errors is off (default)
2023-08-31 14:55:33 +02:00
Remi Collet
1f2cfd8009
ensure displays_errors is off (default) 2023-08-31 14:55:17 +02:00
George Peter Banyard
a3725f12a3 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-11876: ini_parse_quantity() accepts invalid quantities
2023-08-30 21:23:36 +01:00
George Peter Banyard
9b28e521d1 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-11876: ini_parse_quantity() accepts invalid quantities
2023-08-30 21:23:10 +01:00
George Peter Banyard
d229a480ad Fix GH-11876: ini_parse_quantity() accepts invalid quantities
Closes GH-11910
2023-08-30 21:22:13 +01:00
Pierrick Charron
ad2ac6f05f
Prepare for PHP 8.4 2023-08-29 15:25:46 -04:00
Jakub Zelenka
7deb84b7a6
Start PHP 8.4 development cycle 2023-08-29 17:19:01 +01:00
Jakub Zelenka
2eb21b0b1e
Update API versions and numbers 2023-08-29 17:04:24 +01:00
Niels Dossche
a3a3964497 Fix oss-fuzz #61712: assertion failure with error handler during binary op
Because the error handler is invoked after the property is updated,
the error handler has the opportunity to remove it before the property
is returned.

Switching the order around fixes this issue. The comments mention that
the current ordering prevents overwriting the EG(std_property_info)
field in the error handler. EG(std_property_info) no longer exists as it
was removed in 7471c217. Back then a global was used to store the
returned property info, but as this is no longer the case there is no
longer a need to protect against overwriting a global.

Closes GH-12062.
2023-08-28 20:00:49 +02:00
Bob Weinand
b07a2d4714 Address CR comments
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2023-08-28 01:25:12 +02:00
Bob Weinand
cd53ce838a Track HashTableIterators for copy-on-write copies of HashTables
When executing a foreach ($ht as &$ref), foreach calls zend_hash_iterator_pos_ex() on every iteration. If the HashTable contained in the $ht variable is not the tracked HashTable, it will reset the position to the internal array pointer of the array currently in $ht.
This behaviour is generally fine, but undesirable for copy-on-write copies of the iterated HashTable. This may trivially occur when the iterated over HashTable is assigned to some variable, then the iterated over variable modified, leading to array separation, changing the HashTable pointer in the variable. Thus foreach happily restarting iteration.
This behaviour (despite existing since PHP 7.0) is considered a bug, if not only for the behaviour being unexpected to the user, also copy-on-write should not have trivially observable side-effects by mere assignment.

The bugfix consists of duplicating HashTableIterators whenever zend_array_dup() is called (the primitive used on array separation).
When a further access to the HashPosition through the HashTableIterators API happens and the HashTable does not match the tracked one, all the duplicates (which are tracked by single linked list) are searched for the wanted HashTable. If found, the HashTableIterator is replaced by the found copy and all other copies are removed.
This ensures that we always end up tracking the correct HashTable.

Fixes GH-11244.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2023-08-28 01:25:12 +02:00
Máté Kocsis
c934e24197 Fix GH-9967 Add support for generating custom function, class const, and property attributes in stubs 2023-08-26 21:35:31 +02:00
Ilija Tovilo
5ad658bc5e Fix type macros for C++
They are now used in arginfo files.
2023-08-26 21:35:31 +02:00
David CARLIER
69f6c742d8
zend_call_stack_default_size update BSD values. (#12051) 2023-08-26 16:36:02 +01:00
ju1ius
3e0e7e3f90
releases property attributes of internal classes (#11980)
* adds test case for internal class property attribute

* releases property attributes of internal classes
2023-08-24 16:07:00 +02:00
Jakub Zelenka
53aa53f42f
Introduce Zend guard recursion protection
This PR introduces a new way of recursion protection in JSON, var_dump
and friends. It fixes issue in master for __debugInfo and also improves
perf for jsonSerializable in some cases. More info can be found in
GH-10020.

Closes GH-11812
2023-08-24 13:03:14 +01:00
Cristian Rodríguez
782ffd761b
Use a single version of strnlen (#12015)
* Zend: Make zend_strnlen available for use outside zend_compile

* exif: remove local php_strnlen, use zend_strnlen instead

* main: remove local strnlen, use zend_strnlen instead

* phar: remove local strnlen, use zend_strnlen
2023-08-22 17:40:24 +02:00
Peter Kokot
32cdd330f3
Remove unneeded zend_language_parser.h patch (#11974)
This was cleaned in 4cbffd89d9 and
patching the Zend/zend_language_parser.h file to include zend.h is not
needed anymore.
2023-08-22 11:21:42 +02:00
ju1ius
7f1c3bf09b
Adds support for DNF types in internal functions and properties (#11969)
Note that this does not add support for items generated by gen_stubs,
only for items registered dynamically via the Zend API.

Closes GH-10120
2023-08-19 00:11:06 +01:00
Ilija Tovilo
1b9ff16f92
Merge branch 'PHP-8.2'
* PHP-8.2:
  Remove redundant condition
2023-08-17 18:55:51 +02:00
Ilija Tovilo
d016c49cf5
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Remove redundant condition
2023-08-17 18:55:45 +02:00
Ilija Tovilo
dd01c74a6f
Remove redundant condition
Never refactor code just before pushing
2023-08-17 18:54:30 +02:00
Ilija Tovilo
48ede64506
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix segfault in format_default_value due to unexpected enum/object
2023-08-17 18:44:37 +02:00
Ilija Tovilo
9437aa9a8e
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix segfault in format_default_value due to unexpected enum/object
2023-08-17 18:43:49 +02:00
Ilija Tovilo
f78d1d0d10
Fix segfault in format_default_value due to unexpected enum/object
Evaluating constants at comptime can result in arrays that contain objects. This
is problematic for printing the default value of constant ASTs containing
objects, because we don't actually know what the constructor arguments were.
Avoid this by not propagating array constants.

Fixes GH-11937
Closes GH-11947
2023-08-17 18:43:11 +02:00
Pierrick Charron
4467f33e89
PHP-8.2 is now for PHP 8.2.11-dev 2023-08-15 16:08:52 -04:00
Patrick Allaert
6e3f93f2f8
PHP-8.1 is now for PHP 8.1.24-dev 2023-08-15 21:09:58 +02:00
George Peter Banyard
82972f448f Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix various bugs related to DNF types
2023-08-15 17:01:51 +01:00
George Peter Banyard
02a80c5b82 Fix various bugs related to DNF types
- GH-11958: DNF types in trait properties do not get bound properly
 - GH-11883: Memory leak in zend_type_release() for non-arena allocated DNF types
 - Internal trait bound to userland class would not be arena allocated
 - Property DNF types were not properly deep copied during lazy loading

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: ju1ius <jules.bernable@gmail.com>
2023-08-15 15:34:33 +01:00
Ilija Tovilo
ee000ea186
Fix uouv on oom on object allocation
We may OOM during object initialization. In this case, free_obj needs to guard
against NULL values. There may be more cases where this is an issue, these were
the ones I was able to discover via script.

Fixes GH-11734
2023-08-14 11:10:00 +02:00
Cristian Rodríguez
2196e2299f
Use zend_ast_size consistenly (#11955)
* opcache: use zend_ast_size helper in zend_persist_ast

* opcache: use zend_ast_size helper in zend_persist_ast_calc

* Zend: fix zend_ast_size definition

It is better not to use sizeof(struct_with_flexible_array)
and instead rely on offsetof(type, member) like most
other similar wrappers do.
2023-08-14 00:51:14 +02:00
Kamil Tekiela
f907a009f9
Align highlight_string|file with HTML standard and modern browsers
Closes GH-11913
2023-08-12 15:08:28 +01:00
Ilija Tovilo
fc9266a5fc
Move ASAN built to GitHub actions
Cirrus will no longer offer unlimited free builds starting next month. We don't
have an alternative for FreeBSD and ARM, so move what we can for now.

Closes GH-11898
2023-08-09 14:06:36 +02:00
Ilija Tovilo
db4dba6702
Move opnum_start for goto for clarification (#11911)
opnum_start denotes the start of the ZEND_FREE block of skipped consuming
opcodes. Storing the number before zend_compile_expr(..., label_ast) makes it
seem like it denotes the start of the label block. However, label_ast must only
be a zval string AST, and as such never results in an actual opcode.
2023-08-09 11:38:54 +02:00
Peter Kokot
ba35ff0893
Remove unused HAVE_GCC_GLOBAL_REGS shell variable (#11877) 2023-08-08 00:51:56 +02:00
David CARLIER
3e315df6f8 Merge branch 'PHP-8.2' 2023-08-07 19:02:55 +01:00
David CARLIER
e9e5b4c1c8 Merge branch 'PHP-8.1' into PHP-8.2 2023-08-07 19:02:44 +01:00
Kévin Dunglas
96885bc04f fix: handle the GNU specific version of strerror_r
Close GH-11882
2023-08-07 19:01:24 +01:00
Ilija Tovilo
efc73f24c3
Revert "Call cast_object handler from get_properties_for"
This reverts commit 4182813ebf.
2023-08-07 12:58:12 +02:00
Ilija Tovilo
73c5f36f5b
Assert ptr_ptr value of TMP|CONST isn't used (#11865)
We require valid code for compilation to succeed, but these paths should always
be guarded by OPx_TYPE checks and never execute. Add an assertion to verify.
2023-08-03 15:28:19 +02:00
Ilija Tovilo
120ae1719d
Add typed specialization for ZEND_COUNT (#11825) 2023-08-03 12:33:32 +02:00
Ilija Tovilo
3148da8ee1
Add block size support for tracked_malloc (#11856)
This does still deviate from USE_ZEND_ALLOC=0 in that we're not rounding up the
size of the allocation to fixed sizes. Doing so would suppress some
out-of-bounds errors checked by ASAN. Rounding up the size in
_zend_mm_block_size would not be good either as it would break code like
memset(ptr, 0 _zend_mm_block_size(ptr)).
2023-08-03 10:08:41 +02:00
Ilija Tovilo
ae431bbfeb
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix use-of-uninitialized-value in start_fake_frame
2023-08-03 09:50:32 +02:00
Ilija Tovilo
4db025bd86
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix use-of-uninitialized-value in start_fake_frame
2023-08-03 09:50:20 +02:00
Ilija Tovilo
ed27d70d9a
Fix use-of-uninitialized-value in start_fake_frame
Closes GH-11732
2023-08-03 09:49:51 +02:00
George Peter Banyard
fc3df283fb
Zend: Fix memory leak in ++/-- when overloading fetch access
Closes GH-11859
2023-08-02 18:47:08 +01:00
George Peter Banyard
2fbec0974f Fix OSS Fuzz #60734: use-after-free visible in ASAN build 2023-08-01 16:40:25 +01:00
George Peter Banyard
6ae9cf40d1 Fix OSS-fuzz #60709 unseting op via globals
It turns out not just NULL is affected nor -- but also on booleans and this also affects properties
2023-08-01 16:40:25 +01:00
Dmitry Stogov
a95316fc79 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fixed incorrect tracked malloc deallocation
2023-08-01 16:02:08 +03:00
Dmitry Stogov
5abf4f232e Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed incorrect tracked malloc deallocation
2023-08-01 16:01:57 +03:00
Dmitry Stogov
4553258df3 Fixed incorrect tracked malloc deallocation
Fixes ext/ffi/tests/list.phpt failure
2023-08-01 16:01:11 +03:00
Dmitry Stogov
79a8cf1b96 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fixed incorrect QM_ASSIGN elimination
2023-07-31 14:51:14 +03:00
Dmitry Stogov
91dc3e15e9 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed incorrect QM_ASSIGN elimination
2023-07-31 14:51:06 +03:00
Dmitry Stogov
b5f8a7270a Fixed incorrect QM_ASSIGN elimination
Fixes OSS Fuzz #60895
2023-07-31 14:50:13 +03:00
Ilija Tovilo
4182813ebf
Call cast_object handler from get_properties_for
Fixes GH-11547
Closes GH-11583
2023-07-25 17:59:44 +02:00
Ilija Tovilo
127ad70782
Fix open_basedir leak
Fixes oss-fuzz #60741
Closes GH-11780
2023-07-25 17:54:14 +02:00
Dmitry Stogov
869ecf5320 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fixed incorrect QM_ASSIGN elimination
2023-07-24 15:45:28 +03:00
Dmitry Stogov
d6a795b935 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed incorrect QM_ASSIGN elimination
2023-07-24 15:43:21 +03:00
Dmitry Stogov
9fc0eab4b4 Fixed incorrect QM_ASSIGN elimination
Fixes OSS Fuzz #60735
2023-07-24 15:42:30 +03:00
David CARLIER
2778b5d25f
zend vm savee registers support for riscv 64. (#11773)
x8 being already reserved, we can only pull x18 to x27.
2023-07-24 08:25:45 +01:00
David CARLIER
6602ddead5
zend call stack fix freebsd code path. (#11766)
The typo in HAVE_PTHREAD_ATTR_GET_STACK (might be due to pthread_attr_get_np being different from Linux's pthread_getattr_np) led to this code path never get called on FreeBSD.
2023-07-23 18:55:14 +01:00
Peter Kokot
9911ab7142
Remove unused ZEND_STACK_GROWS_DOWNWARDS constant (#11762) 2023-07-22 19:39:42 +02:00
Niels Dossche
d58e3c05c9 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-11716: cli server crashes on SIGINT when compiled with ZEND_RC_DEBUG=1
2023-07-21 15:31:33 +02:00
Niels Dossche
272dc9a09c Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11716: cli server crashes on SIGINT when compiled with ZEND_RC_DEBUG=1
2023-07-21 15:31:20 +02:00
Niels Dossche
af77d3b8da Fix GH-11716: cli server crashes on SIGINT when compiled with ZEND_RC_DEBUG=1
Closes GH-11757.
2023-07-21 15:23:56 +02:00
Peter Kokot
b132b7ab7e
Remove check for time.h and HAVE_TIME_H (#11726)
The `<time.h>` header file is part of the standard C89 headers [1] and
on current systems can be included unconditionally.

The conditional include based on Windows is there so the win32/time.h
can be included on other places when needed.

Refs:
[1] https://port70.net/~nsz/c/c89/c89-draft.html#4.1.2
[2] https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/headers.m4
2023-07-20 09:38:53 +02:00
Ilija Tovilo
b0037eda26
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix use-after-free when unregistering user stream wrapper from itself
2023-07-19 11:20:18 +02:00
Ilija Tovilo
c3ccc363c6
Fix use-after-free when unregistering user stream wrapper from itself
Fixes GH-11735
Closes GH-11737
2023-07-19 11:17:57 +02:00
Ben Ramsey
6e3c520f51
PHP-8.1 is now for PHP-8.1.23-dev 2023-07-18 16:30:49 -05:00
Máté Kocsis
c322da0606
Fix misleading pass by reference error message (#10639) 2023-07-18 15:02:38 +02:00
Ilija Tovilo
9bcdf219ec
Resolve open_basedir paths on ini update
Closes GH-10987
2023-07-18 14:43:40 +02:00
Sergey Panteleev
796a75f967
PHP-8.2 is now for PHP 8.2.10-dev 2023-07-18 14:02:43 +03:00
Máté Kocsis
d9a7f6741e Deprecate ReflectionProperty::setValue() with an incorrect 1st arg type 2023-07-18 12:59:21 +02:00
Máté Kocsis
1126232053 Deprecate calling get_class() and get_parent_class() without arguments 2023-07-18 12:59:21 +02:00
Ilija Tovilo
1057cce1c0
Always memoize calls in lhs of coalesce assignment
We don't want to invoke calls twice, even if they are considered "variables",
i.e. might be writable if returning a reference. Function calls behave the same
in all BP contexts so they don't need to be invoked twice. The singular
exception to this is nullsafe coalesce in isset/empty, because it needs to
return false/true respectively when short-circuited. However, since nullsafe
calls are not allwed in write context we may ignore this problem.

Closes GH-11592
2023-07-18 12:48:00 +02:00
Gabriel Fontes
cd9dba81c7 small fixes 2023-07-18 08:31:02 +01:00
Ilija Tovilo
a48b977d3f Use :- as ini interpolation fallback separator 2023-07-18 08:31:02 +01:00
Gabriel Fontes
bc8b9aedf6 Add fallback value syntax for ini variables 2023-07-18 08:31:02 +01:00
Ilija Tovilo
0b0cec5b8a
Fix clang warning
has_range_constraint should can be a bool, remove unused visited field.

Closes GH-11729
2023-07-18 00:49:13 +02:00
Ilija Tovilo
1a0ef2c1cc
Revert "Remove name field from the zend_constant struct (#10954)"
This reverts commit f42992f580.

Closes GH-11604
2023-07-17 22:32:41 +02:00
George Peter Banyard
d8696f9216
[RFC] Path to Saner Increment/Decrement operators (#10358)
* Add behavioural tests for incdec operators

* Add support to ++/-- for objects castable to _IS_NUMBER

* Add str_increment() function

* Add str_decrement() function

RFC: https://wiki.php.net/rfc/saner-inc-dec-operators

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Arnaud Le Blanc <arnaud.lb@gmail.com>
2023-07-17 15:51:24 +01:00
Ilija Tovilo
1c76da62db
Fix gc_status type info
Closes GH-11722
2023-07-17 13:49:23 +02:00
George Peter Banyard
3e2dbbf9c2 Add support for deprecating class constants 2023-07-17 05:01:13 +01:00
Arnaud Le Blanc
cbf67e4fee
Remove WeakMap entries whose key is only reachable through the entry value (#10932) 2023-07-16 13:39:08 +02:00
Arnaud Le Blanc
d0731934b7
Expose time spent collecting cycles in gc_status() (#11523) 2023-07-16 12:34:28 +02:00
George Peter Banyard
3d4ff5ae22
RFC: Deprecate remains of string evaluated code assertions (#11671)
Link: https://wiki.php.net/rfc/assert-string-eval-cleanup
2023-07-13 15:45:32 +01:00
David CARLIER
a077c2dd6c Merge branch 'PHP-8.2' 2023-07-13 12:40:59 +01:00
David CARLIER
0309800b4d Merge branch 'PHP-8.1' into PHP-8.2 2023-07-13 12:40:47 +01:00
David Carlier
69b4360e88 zend_gdb disable gdb detection for FreeBSD < 11.
ref PR: https://github.com/php/php-src/pull/11599.

Close GH-11646
2023-07-13 12:39:58 +01:00
Ilija Tovilo
d9db446065
Fix iface const visibility variance check 2023-07-13 10:52:58 +02:00
Ilija Tovilo
7343ae5d3c
Fix missing iface class const inheritance type check 2023-07-13 10:40:19 +02:00
Ilija Tovilo
c1a7058e66
Merge branch 'PHP-8.2'
* PHP-8.2:
  Always memoize assert
2023-07-12 16:36:14 +02:00
Ilija Tovilo
6d98c085a1
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Always memoize assert
2023-07-12 16:36:08 +02:00
Ilija Tovilo
b1b7c61a27
Always memoize assert
Closes GH-11686
2023-07-12 16:35:09 +02:00
Ilija Tovilo
a833937725
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix double-compilation of arrow-function
2023-07-12 11:01:38 +02:00
Ilija Tovilo
060df83a98
Fix double-compilation of arrow-function
We transform the arrow function by nesting the expression into a return
statement. If we compile the arrow function twice this would be done twice,
leading to a compile assertion.

Fix oss-fuzz #60411
Closes GH-11632
2023-07-12 11:01:23 +02:00
Niels Dossche
3d944a367e Update type inference for ZEND_STRLEN
Since PHP 8.0, this cannot return NULL anymore, the only possible return
value is long. See https://wiki.php.net/rfc/consistent_type_errors.
2023-07-10 11:04:00 +02:00
Niels Dossche
838d80e7ee Update type inference for ZEND_GET_CLASS and ZEND_GET_CALLED_CLASS
These cannot return false anymore since PHP 8.0.
2023-07-10 11:03:43 +02:00
David Carlier
343b599747 zend call stack, follow-up on 75e9980.
user stack usable implementation for openbsd.

Close GH-11626
2023-07-08 15:32:57 +01:00
David CARLIER
75e9980054
zend stack: prepare zend_call_stack_get implementation for OpenBSD. (#11578) 2023-07-07 18:03:07 +01:00
Niels Dossche
0b2e6bc2b0 Cache d_type in directory entry 2023-07-07 18:02:32 +02:00
Arnaud Le Blanc
72a163aa90
Add stack limit check in zend_eval_const_expr() (#11424) 2023-07-07 14:18:15 +02:00
Ilija Tovilo
11aee73572
Fix incorrect handling of unwind and graceful exit exceptions
These exceptions should not invoke the user error handler, and not cause bailing
of the request.

Fixes GH-11601
Closes GH-11608
2023-07-07 08:15:17 +02:00
Ilija Tovilo
dbbcbcb5b5
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix use-of-uninitialized-value with ??= on assert
2023-07-06 09:39:46 +02:00
Ilija Tovilo
ac3ff5bb7a
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix use-of-uninitialized-value with ??= on assert
2023-07-06 09:39:05 +02:00
Ilija Tovilo
84a2e48050
Fix use-of-uninitialized-value with ??= on assert
Normally, PHP evaluates all expressions in offsets (property or array), as well
as the right hand side of assignments before actually fetching the offsets. This
is well explained in this blog post.

https://www.npopov.com/2017/04/14/PHP-7-Virtual-machine.html#writes-and-memory-safety

For ??= we have a bit of a problem in that the rhs must only be evaluated if the
lhs is null or undefined. Thus, we have to first compile the lhs with BP_VAR_IS,
conditionally run the rhs and then re-fetch the lhs with BP_VAR_W to to make
sure the offsets are valid if they have been invalidated.

However, we don't want to just re-evaluate the entire lhs because it may contain
side-effects, as in $array[$x++] ??= 42;. In this case, we don't want to
re-evaluate $x++ because it would result in writing to a different offset than
was previously tested. The same goes for function calls, like
$array[foo()] ??= 42;, where the second call to foo() might result in a
different value. PHP behaves correctly in these cases. This is implemented by
memoizing sub-expressions in the lhs of ??= and reusing them when compiling the
lhs for the second time. This is done for any expression that isn't a variable,
i.e. anything that can (potentially) be written to.

Unfortunately, this also means that function calls are considered writable due
to their return-by-reference semantics, and will thus not be memoized. The
expression foo()['bar'] ??= 42; will invoke foo() twice. Even worse,
foo(bar()) ??= 42; will call both foo() and bar() twice, but
foo(bar() + 1) ??= 42; will only call foo() twice. This is likely not by design,
and was just overlooked in the implementation. The RFC does not specify how
function calls in the lhs of the coalesce assignment behaves. This should
probably be improved in the future.

Now, the problem this commit actually fixes is that ??= may memoize expressions
inside assert() function calls that may not actually execute. This is not only
an issue when using the VAR in the second expression (which would usually also
be skipped) but also when freeing the VAR. For this reason, it is not safe to
memoize assert() sub-expressions.

There are two possible solutions:

1. Don't memoize any sub-expressions of assert(), meaning they will execute
   twice.
2. Throw a compile error.

Option 2 is not quite simple, because we can't disallow all memoization inside
assert(), as that would break assertions like assert($array[foo()] ??= 'bar');.
Code like this is highly unlikely (and dubious) but possible. In this case, we
would need to make sure that a memoized value could not be used across the
assert boundary it was created in. The complexity for this is not worthwhile. So
we opt for option 1 and disable memoization immediately inside assert().

Fixes GH-11580
Closes GH-11581
2023-07-06 09:38:41 +02:00