1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

324 Commits

Author SHA1 Message Date
Gina Peter Banyard
f40b356ad9 Use smart_str_append() if we have a zend_string* (#21414) 2026-03-21 17:06:14 +00:00
Arshid
b5abd77bdf [skip ci] Remove unreachable code after zend_error_noreturn calls (GH-21122) 2026-02-03 22:02:43 +01:00
Arnaud Le Blanc
d16e6f52a4 Generate C enums from internal enums, introduce Z_PARAM_ENUM() (#20917)
Update gen_stubs.php to generate C enums from internal enums, when the stub is annotated with @generate-c-enums. Enum values can be compared to the result of zend_enum_fetch_case_id(zend_object*).

The generated enums are added to separate files named {$extensionName}_decl.h, so that it's possible to include these from anywhere. _arginfo.h files would generate warnings if we tried to include them in a compilation unit that doesn't call the register_{$class} functions, for instance.

Introduce Z_PARAM_ENUM().

* Make ZEND_AST_CONST_ENUM_INIT a 4-children node

* Store enum case id in ZEND_AST_CONST_ENUM_INIT

* Store enum case id in instance

* Expose enum case_id internally

* Generate C enum for internal enums

* Introduce Z_PARAM_ENUM()

* Port extensions
2026-02-03 12:38:04 +01:00
Arshid
6a0871853b Drop unused priority argument from zend_ast_export_var() (GH-21096) 2026-01-30 21:44:16 +01:00
Ilija Tovilo
db24ca5926 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix segfault when preloading constant AST closure
2026-01-29 13:31:38 +01:00
Ilija Tovilo
2f2b421a48 Fix segfault when preloading constant AST closure
Fixes GH-21059
Closes GH-21071
2026-01-29 13:30:41 +01:00
Ilija Tovilo
1075182118 Fix "fptr may be used uninitialized" warning
Older versions of GCC seem to get confused about the call to
zend_ast_call_get_args(ast), and assume it may mutate ast, even though it is
local.
2026-01-13 13:15:31 +01:00
Arnaud Le Blanc
ef522525cf Introduce zend_ast_call_get_args() (#20859) 2026-01-08 11:46:10 +01:00
Arnaud Le Blanc
5472cac806 Support PFA syntax
RFC: https://wiki.php.net/rfc/partial_function_application_v2

For FCCs, the parser generates a normal function call AST node, the but argument
list is a ZEND_AST_CALLABLE_CONVERT / zend_ast_fcc node.

We extend this for PFAs so that zend_ast_fcc can represent arguments.

 * Support PFA syntax in grammar
 * Update zend_ast_fcc so that arguments can be represented
 * Support serialization of zend_ast_fcc arguments in SHM / file cache
 * Introduce zend_ast_arg_list_add(): Same as zend_ast_list_add(), but wraps the
   list in a ZEND_AST_CALLABLE_CONVERT when adding any placeholder argument.

Technically the arg list wrapping is not required, but it results in simpler
code later as it will be very convenient in the compiler (determines whether a
function calls is a PFA/FCC), and for PFA-in-const-expr support. It also allows
to unify FCCs and PFAs in the grammar.

Closes GH-20717.
2026-01-06 12:01:48 +01:00
Arnaud Le Blanc
833120eb72 Trim WS 2025-12-18 10:55:05 +01:00
Gina Peter Banyard
d77d44e1f7 Zend: Mark zend_ast_evaluate_inner as static (#19950)
As this function is not exported in a header
2025-09-24 18:54:05 +01:00
Tim Düsterhus
c9b175992c Zend: Use true / false instead of 1 / 0 for bool parameters
Changes done with Coccinelle:

    @r1@
    identifier F;
    identifier p;
    typedef bool;
    parameter list [n1] PL1;
    parameter list [n2] PL2;
    @@

    F(PL1, bool p, PL2) {
    ...
    }

    @r2@
    identifier r1.F;
    expression list [r1.n1] EL1;
    expression list [r1.n2] EL2;
    @@

    F(EL1,
    (
    - 1
    + true
    |
    - 0
    + false
    )
    , EL2)
2025-09-24 18:51:40 +02:00
Tim Düsterhus
ef1b5ae61b Zend: Use return true / return false for functions returning bool
Changes done with Coccinelle:

    @r1@
    identifier fn;
    typedef bool;
    symbol false;
    symbol true;
    @@

    bool fn ( ... )
    {
    <...
    return
    (
    - 0
    + false
    |
    - 1
    + true
    )
    ;
    ...>
    }

Coccinelle patch sourced from
torvalds/linux@46b5c9b856.
2025-09-24 18:51:40 +02:00
Tim Düsterhus
c93b467b37 zend_ast: Fix Closure scope for FCC in constant expression (#19639)
Fixes php/php-src#19637
2025-09-01 21:20:37 +02:00
Tim Düsterhus
6ba5f7e195 zend_ast: Mark zend_ast_list_add() as ZEND_ATTRIBUTE_NODISCARD (#19632)
* zend_portability: Add `ZEND_ATTRIBUTE_NODISCARD`

* zend_ast: Mark `zend_ast_list_add()` as `ZEND_ATTRIBUTE_NODISCARD`

This actually caught a bug in the implementation of attributes on regular
constants: A list of 4 constants with an attribute did not correctly result in
an error, since the reallocated list wasn't stored anywhere.

* zend_portability: Support C++ for `ZEND_ATTRIBUTE_NODISCARD`

Co-authored-by: David CARLIER <devnexen@gmail.com>

---------

Co-authored-by: David CARLIER <devnexen@gmail.com>
2025-08-29 19:57:04 +02:00
Ilija Tovilo
71a3226a46 Prohibit pipe & arrow function combination that leads to confusing parse trees
See https://externals.io/message/128473
Closes GH-19533
2025-08-25 17:24:55 +02:00
Gina Peter Banyard
3bf21a0d43 Zend: Deprecate non-canonical cast names (#19372)
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_non-standard_cast_names
2025-08-08 21:22:49 +01:00
Gina Peter Banyard
d0274e74f8 Zend/zend_ast: Use uint32_t type instead of int type 2025-08-05 12:43:18 +01:00
Gina Peter Banyard
8512514a0f Zend/zend_ast: Use zend_ast_get_list() instead of cast 2025-08-05 12:43:18 +01:00
Gina Peter Banyard
36ec3370fb Zend/zend_ast: Add const qualifier 2025-08-05 12:43:18 +01:00
Ilija Tovilo
03e2613ddd Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix failed assertion with throwing __toString in binary const expr
2025-07-30 13:34:43 +02:00
Ilija Tovilo
138ebf481b Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix failed assertion with throwing __toString in binary const expr
2025-07-30 13:34:32 +02:00
Ilija Tovilo
80022c035b Fix failed assertion with throwing __toString in binary const expr
Solve this with the same pattern as ZEND_AST_GREATER[_EQUAL].

Fixes OSS-Fuzz #434346548
Closes GH-19291
2025-07-30 13:34:01 +02:00
Tim Düsterhus
45d948f2da Zend: Add zend_check_method_accessible() to DRY method visibility checks (#18995)
* Zend: Add `zend_check_method_accessible()` to DRY method visibility checks

* Zend: Add assertions verifying flags didn't change before `zend_check_method_accessible()`

* Try `zend_always_inline` for `zend_check_method_accessible`
2025-07-07 21:30:13 +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
Nikita Popov
910411f2f5 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix line assignment in zend_ast_create_va()
2025-06-01 20:36:01 +02:00
Nikita Popov
d66e87b02e Fix line assignment in zend_ast_create_va()
The intent here was to assign the first found line. Instead this
always fell back to CG(zend_lineno).

Not sure if this line matters for anything in php-src, but the
issue was observed in https://github.com/nikic/php-ast/issues/247.
2025-06-01 20:35:35 +02:00
Daniel Scherzer
6b95875dc5 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18695: float numbers zero fraction is now preserved in zend_ast_export() (#18699)
2025-05-29 13:49:34 -07:00
Daniel Scherzer
e44c13cffe Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18695: float numbers zero fraction is now preserved in zend_ast_export() (#18699)
2025-05-29 13:48:38 -07:00
Oleg Efimov
087f38f347 Fix GH-18695: float numbers zero fraction is now preserved in zend_ast_export() (#18699) 2025-05-29 13:46:11 -07:00
DanielEScherzer
f0fa9c748a zend_ast.c: use smart_str_appendc for appending single characters (#18703)
Slightly more performant
2025-05-29 11:11:00 -07:00
Dmitrii Derepko
fdebad0b25 zend_ast: Add parentheses around IIFE in zend_ast_export() (#18688) 2025-05-29 15:47:47 +02:00
Niels Dossche
0b48e2a267 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix OSS-Fuzz #418106144
  Fix OSS-Fuzz #417078295
  fix: dangling opline in ZEND_INIT_ARRAY (#18578)
2025-05-19 19:08:29 +02:00
Niels Dossche
08cba2dcc1 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix OSS-Fuzz #418106144
  Fix OSS-Fuzz #417078295
2025-05-19 19:07:17 +02:00
Niels Dossche
98cb17f4fd Fix OSS-Fuzz #418106144
The VM assumes that an exception must be handled when the AST evaluation
returns FAILURE. However, the comparison functions always return SUCCESS
even if an exception happened. This can be fixed in
zend_ast_evaluate_inner() or we can make is_smaller_function() etc check
for the exception. I chose the former to avoid impact or API breaks.
Perhaps in the future the comparison functions should either return void
or return whether an exception happened, as to be not misleading.

Closes GH-18589.
2025-05-19 19:05:32 +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
Niels Dossche
2f6c069296 Implement GH-18261: Allow cast to be used in constant expressions (#18264) 2025-04-11 17:53:43 +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
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
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
Tim Düsterhus
d8d1cb4195 zend_ast: Print placeholder value when printing ZEND_AST_OP_ARRAY (#17405)
As per the discussion in GH-17120, we are printing a placeholder value only.
The commit history of that PR also includes alternative implementations, should
a different decision be desirable.

Fixes GH-17096
Closes GH-17120
2025-01-10 08:37:17 +01:00
Tim Düsterhus
e421a44ac6 zend_ast: Remove unused ZEND_AST_EXIT (#17417)
This AST node is no longer used since `exit()` was made a real function in
GH-13483.
2025-01-09 12:23:33 +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
97f44b7c39 Merge branch 'PHP-8.4'
* PHP-8.4:
  Export visibility for promoted property (8.3)
  [ci skip] News for GH-17101
  Add test for GH-17101
  Print hooks in parameter exports
  Fix property hook name mismatch
  Extract hook export code
  Export visibility for promoted property
2024-12-17 19:14:55 +01:00
Niels Dossche
160a4a65ad Export visibility for promoted property (8.3) 2024-12-17 19:14:07 +01:00
Niels Dossche
3f0f7ab7df Print hooks in parameter exports 2024-12-17 19:06:10 +01:00