Commit graph

2973 commits

Author SHA1 Message Date
Ilija Tovilo
9460dbe906
Fix lineno for constructor property promotion errors
Fixes GH-19081
Closes GH-19100
2025-07-12 19:15:48 +02:00
Niels Dossche
8712f4bf19
Fix OSS-Fuzz #427814452
Pipe compilation uses a temporary znode with QM_ASSIGN to remove
references. Assert compilation wants to look at the operand AST and
convert it to a string. However the original AST is lost due to the
temporary znode. To solve this we either have to handle this specially
in pipe compilation [1], or store the AST anyway somehow.
Special casing this either way is not worth the complexity in my
opinion, especially as it looks like a dynamic call anyway due to the
FCC syntax.

[1] Prototype (incomplete) at
    https://gist.github.com/nielsdos/50dc71718639c3af05db84a4dea6eb71
    shows this is not worthwhile in my opinion.

Closes GH-18965.

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2025-07-12 09:51:27 +02:00
Tim Düsterhus
ca49a7bec2
RFC: Turn clone() into a function (#18919)
RFC: https://wiki.php.net/rfc/clone_with_v2

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-06-24 20:14:40 +02:00
DanielEScherzer
4dfba7a250
[RFC] Final Property Promotion
https://wiki.php.net/rfc/final_promotion
2025-06-22 12:29:26 -07:00
Larry Garfield
1c09c0c832
RFC: Pipe operator (#17118)
Co-authored-by: Gina Peter Banyard <girgias@php.net>
Co-authored-by: Arnaud Le Blanc <arnaud.lb@gmail.com>
Co-authored-by: Tim Düsterhus <tim@tideways-gmbh.com>
2025-06-10 09:59:43 +02:00
Tim Düsterhus
3e37bcedf4
[skip ci] Trim trailing whitespace in zend_compile.c
Introduced in 5544be7018. Trimming to simplify
the diff of the pipe operator RFC implementation.
2025-06-10 09:05:37 +02:00
DanielEScherzer
3f03f7ed3d
[RFC] Add support for attributes on compile-time constants
https://wiki.php.net/rfc/attributes-on-constants
2025-04-29 11:53:09 -07:00
Ilija Tovilo
c97bdce962
Evaluate const expression cast at ct if possible
Related to GH-18264
Closes GH-18347
2025-04-22 17:49:33 +02:00
Ilija Tovilo
87499e44f2
Fix use of magic const within const expr cast (GH-18338)
Fixes OSS-Fuzz #410939023
2025-04-16 20:00:40 +02:00
Tim Düsterhus
9ac8820fc9
zend_compile: Allow (void) in for’s initializer and loop expression (#18303)
* zend_compile: Allow `(void)` in for’s initializer and loop expression

The initializer and loop expression of a `for()` loop only accept expressions,
but they act like statements in spirit - their results are completely ignored.
Allow `(void)` there to allow suppressing `#[\NoDiscard]`, since there is no
semantic ambiguity of what `(void)` returns anyways.

Fixes php/php-src#18301

* zend_language_parser: Simplify `for()` grammar
2025-04-14 15:36:51 +02:00
Niels Dossche
2f6c069296
Implement GH-18261: Allow cast to be used in constant expressions (#18264) 2025-04-11 17:53:43 +02:00
Niels Dossche
a32f491855
Remove cache slot from ZEND_VERIFY_TYPE and arg RECV opcodes (#18258) 2025-04-07 19:50:48 +02:00
Gina Peter Banyard
71da944c82 Zend: Add MUTABLE zend_type foreach macros and const qualifiers
The motivation for this is that types should be considered immutable.
The only times this is not valid is during compilation, optimizations (opcache), or destruction.

Therefore the "normal" type foreach macros are marked to take const arguments and we add mutable version that say so in the name.
Thus add various const qualifiers to communicate intent.
2025-04-07 12:52:40 +01:00
Ilija Tovilo
1f6fdde646
Implement asymmetric visibility for static properties
https://wiki.php.net/rfc/static-aviz

Optimally, this would be moved to zend_fetch_static_property_address(). However,
this isn't currently effective for opcache, because R and RW/W/UNSET cache slots
are merged. This will circumvent the visibility check if the cache is primed by
a R instruction.

Closes GH-16486
2025-04-02 16:56:11 +02:00
Tim Düsterhus
5544be7018
RFC: Marking return values as important (#[\NoDiscard]) (#17599)
RFC: https://wiki.php.net/rfc/marking_return_value_as_important

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-04-02 09:35:29 +02:00
Tim Düsterhus
45d1acf916
Zend: Fix reference counting for Closures in const-expr (#17853)
* Clean up closure static variable handling

* Zend: Fix reference counting for Closures in const-expr

Fixes php/php-src#17851

---------

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2025-03-27 10:11:44 +01:00
Ilija Tovilo
99f72fa499
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix infinite recursion on deprecated attribute evaluation
2025-03-26 23:40:58 +01:00
Ilija Tovilo
272f7f75e2
Fix infinite recursion on deprecated attribute evaluation
Fixes GH-17711
Fixes GH-18022
Closes GH-17712
2025-03-26 23:39:38 +01:00
Tim Düsterhus
8779e2a603 Add (void) cast
RFC: https://wiki.php.net/rfc/marking_return_value_as_important
2025-03-24 19:35:30 +01:00
Niels Dossche
e4be679780
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix OSS-Fuzz #403308724
2025-03-16 13:45:33 +01:00
Niels Dossche
4fd9992561
Fix OSS-Fuzz #403308724
Because simple hooks can be nested without starting a new context, we
need to restore the old property info in case of nested hooks.

Closes GH-18074.
2025-03-16 13:42:40 +01:00
Niels Dossche
229c1ebb67
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17916: Final abstract properties should error
2025-02-24 20:19:24 +01:00
Daniel Scherzer
c0857e0d8a
Fix GH-17916: Final abstract properties should error
Closes GH-17917.
2025-02-24 20:17:41 +01:00
Tim Düsterhus
2042fd34e0
Support first-class callables in const-expressions (#17213)
RFC: https://wiki.php.net/rfc/fcc_in_const_expr

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-02-20 18:52:47 +01:00
Gina Peter Banyard
65d433161a
Use new known "self" and "parent" zend_strings (#17766) 2025-02-12 15:30:55 +00:00
Gina Peter Banyard
1ad7743133
Zend: Resolve self and parent types at compile time (#17755)
This does not apply to traits.
2025-02-11 15:15:32 +00:00
Ilija Tovilo
fa7c67d622
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix stack overflow detection for variable compilation
2025-01-29 23:28:22 +01:00
Ilija Tovilo
4f91af38cc
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix stack overflow detection for variable compilation
2025-01-29 23:28:16 +01:00
Ilija Tovilo
333f5dd848
Fix stack overflow detection for variable compilation
Closes GH-17623
2025-01-29 23:27:27 +01:00
Niels Dossche
75bd1a9dc0
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix may_have_extra_named_args flag for ZEND_AST_UNPACK
2025-01-21 19:27:24 +01:00
Niels Dossche
0b12db6afa
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix may_have_extra_named_args flag for ZEND_AST_UNPACK
2025-01-21 19:27:19 +01:00
Niels Dossche
0b3e637aec
Fix may_have_extra_named_args flag for ZEND_AST_UNPACK
The check for `!fbc || (fbc->common.fn_flags & ZEND_ACC_VARIADIC)` is
performed after `fbc` is set to NULL, so this always returns true.
This results in `ZEND_FCALL_MAY_HAVE_EXTRA_NAMED_PARAMS` always being
set for unpack sends. Fix it by moving the flag updates to the point
before setting `fbc` to NULL.

Closes GH-17534.
2025-01-21 19:26:49 +01:00
Ilija Tovilo
e95b298262
Store prop info name in CG(context) instead of prop info
The prop info is not always available, e.g. when compiling the default
value.

See GH-17378
Closes GH-17464
2025-01-14 17:01:10 +01:00
Ilija Tovilo
a06668af30
Merge branch 'PHP-8.4'
* PHP-8.4:
  __PROPERTY__ does not work in all constant expression contexts
2025-01-13 16:43:32 +01:00
Ilija Tovilo
147e9c808c
__PROPERTY__ does not work in all constant expression contexts
Fixes GH-17222
Closes GH-17378
2025-01-13 16:42:38 +01:00
Tim Düsterhus
cee64ed3bd
Add dedicated zend_ast_op_array struct (#17391)
Given that the `ZEND_AST_OP_ARRAY` type already needed special handling in
various places, it makes sense to give it its own struct to avoid some of the
casts. As a side benefit, it is a little smaller than the `zend_ast_zval`
struct.
2025-01-08 11:26:35 +01:00
Tim Düsterhus
fd1eacc2ed
Add assertions verifying that zend_ast_decl AST nodes are not treated as regular zend_ast nodes (#17390)
* zend_compile: Do not traverse children of ZEND_AST_CLOSURE in zend_compile_const_expr()

* Add assertions verifying that zend_ast_decl AST nodes are not treated as regular zend_ast nodes
2025-01-08 10:36:02 +01:00
Niels Dossche
cc4402b6cb
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17234: Numeric parent hook call fails with assertion
2025-01-07 19:21:35 +01:00
Niels Dossche
71493623f4
Fix GH-17234: Numeric parent hook call fails with assertion
The current code expects the property name to be a string, but it can
also be a number via the {} syntax. Handle this consistently to a string
by using zval_get_string which will do the type coercion and refcount
update (instead of assuming string and doing an explicit string copy).

Closes GH-17236.
2025-01-07 19:21:22 +01:00
Ilija Tovilo
fbb97aa6fc
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix unstable get_iterator pointer for hooked classes in shm on Windows
2024-12-09 17:14:46 +01:00
Ilija Tovilo
792f63df45
Fix unstable get_iterator pointer for hooked classes in shm on Windows
Closes GH-17034
2024-12-09 17:14:19 +01:00
Tim Düsterhus
f6a0bb4d04
Support Closures in constant expressions (#16458)
RFC: https://wiki.php.net/rfc/closures_in_const_expr

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Arthur Kurbidaev <artkurbidaev@gmail.com>
2024-12-02 18:25:43 +01:00
Christoph M. Becker
fdd3839d80
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix potential OOB read in zend_dirname() on Windows
2024-11-29 22:11:27 +01:00
Christoph M. Becker
ba7dee5676
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix potential OOB read in zend_dirname() on Windows
2024-11-29 22:11:00 +01:00
Christoph M. Becker
65070bb46c
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix potential OOB read in zend_dirname() on Windows
2024-11-29 22:09:40 +01:00
Christoph M. Becker
94fa2a4ce1
Fix potential OOB read in zend_dirname() on Windows
Only on Windows `IS_SLASH_P()` may read the previous byte, and so may
in unlikely cases read one byte out of bounds.  Since `IS_SLASH_P()` is
in a public header (albeit not likely to be used by external extensions
or SAPIs), we introduce `IS_SLASH_P_EX()` which accepts a second
argument to prevent that OOB read.

It should be noted that the PHP userland function `dirname()` is not
affected by this issue, since it does not call `zend_dirname()` on
Windows.

Closes GH-16995.
2024-11-29 22:08:06 +01:00
Ilija Tovilo
f44eaac48a
Simplify duplicate member flag check (GH-16874) 2024-11-21 14:54:57 +01:00
Niels Dossche
dfba04e807
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-16727: Opcache bad signal 139 crash in ZTS bookworm (frankenphp)
2024-11-11 16:20:44 +01:00
Niels Dossche
382be923ae
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16727: Opcache bad signal 139 crash in ZTS bookworm (frankenphp)
2024-11-11 16:20:39 +01:00
Niels Dossche
fbf4cec63b
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16727: Opcache bad signal 139 crash in ZTS bookworm (frankenphp)
2024-11-11 16:20:30 +01:00