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

1598 Commits

Author SHA1 Message Date
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
Arnaud Le Blanc
65b4073922 Include the actual stub name in generated arginfo headers (#20993) 2026-01-21 20:57:00 +01:00
Tim Düsterhus
175b7bca8c Merge branch 'PHP-8.5'
* PHP-8.5:
  zend_language_parser: Backup / restore doc comment when parsing attributes (#20896)
2026-01-13 16:08:15 +01:00
Tim Düsterhus
11ae6ad0be zend_language_parser: Backup / restore doc comment when parsing attributes (#20896)
Attributes may themselves contain elements which can have a doc comment on
their own (namely Closures). A doc comment before the attribute list is
generally understood as belonging to the symbol having the attributes.

Fixes php/php-src#20895.
2026-01-13 16:07:50 +01:00
Daniel Scherzer
c0b16e080b reflection: set key_initialized global to proper booleans (#20691)
Instead of using `1` and `0`, use `true` and `false`
2025-12-17 21:14:57 -08:00
Arnaud Le Blanc
626f3c3c7c Unify arg info representation for internal and user functions
The arg_info member of zend_function is now always a zend_arg_info*. Before,
it was a zend_internal_arg_info* on internal functions, unless the
ZEND_ACC_USER_ARG_INFO flag was set.

Closes GH-19022
2025-12-15 16:50:49 +01:00
Daniel Scherzer
8fa4bf05ec Merge branch 'PHP-8.5'
* PHP-8.5:
  Add "since PHP 8.1" to ReflectionXxx::setAccessible() deprecations (#20555)
2025-12-01 12:57:50 -08:00
Michael Voříšek
f8c7dc19a4 Add "since PHP 8.1" to ReflectionXxx::setAccessible() deprecations (#20555) 2025-12-01 12:57:19 -08:00
Niels Dossche
157864af49 reflection: Use zend_hash_find_ptr_lc() where possible 2025-11-30 01:39:21 -08:00
Niels Dossche
13bf672cdb reflection: Use zend_hash_str_find_ptr_lc() where possible 2025-11-30 01:39:21 -08:00
Niels Dossche
e025f2a148 reflection: Test ReflectionFunction::__toString() with bound variables (#20608) 2025-11-30 10:39:04 +01:00
Niels Dossche
b64cd429ca reflection: Use RETURN_COPY_VALUE() 2025-11-30 01:38:53 -08:00
Niels Dossche
b074c5cc55 reflection: Remove dead code
Since the executor needs to be active at this point, the only way you
could get an UNDEF return value is by having an exception.
Therefore, `!EG(exception)` is always false.
The check doesn't make sense, remove it.
2025-11-30 01:38:53 -08:00
Alexandre Daubois
206395fa5f Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-20217: ReflectionClass::isIterable() should return false for classes with property hooks (#20241)
2025-10-22 10:04:02 +02:00
Alexandre Daubois
39d5cbb13d Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-20217: ReflectionClass::isIterable() should return false for classes with property hooks (#20241)
2025-10-22 10:03:00 +02:00
Alexandre Daubois
572652e5de Fix GH-20217: ReflectionClass::isIterable() should return false for classes with property hooks (#20241) 2025-10-22 10:01:35 +02:00
Niels Dossche
57ce245e1e Reduce code bloat in arginfo by using specialised string releases (#20016)
* Reduce code bloat in arginfo by using specialised string releases

Comparing this patch to master (c7da728574),
with a plain configure command without any options:

```
   text	   data	    bss	    dec	    hex	filename
20683738	1592400	 137712	22413850	156021a	sapi/cli/php
20688522	1592400	 137712	22418634	15614ca	sapi/cli/php_old
```

We see a minor reduction of 0.023% in code size.

* Also use true for the other initialization line

* Also use specialized code for consts
2025-10-02 22:00:20 +02:00
Tim Düsterhus
8e66b4eaf1 reflection: 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
cdb8321e21 reflection: Use true / false instead of 1 / 0 when assigning to bool
Changes done with Coccinelle:

    @@
    bool b;
    @@

    - b = 0
    + b = false

    @@
    bool b;
    @@

    - b = 1
    + b = true
2025-09-24 18:51:40 +02:00
sasezaki
78c997f36f Make ReflectionConstant non-final
Fixes GH-19747
Closes GH-19901
2025-09-22 19:52:59 +02:00
Daniel Scherzer
c34558d125 GH-19691: Add asymmetric visibility to Reflection::getModifierNames() (#19697) 2025-09-04 23:00:36 -07:00
Ilija Tovilo
6497c6c455 Don't substitute self/parent with anonymous class
Fixes GH-18373
Closes GH-19537
2025-08-25 17:08:29 +02:00
Daniel Scherzer
1cbaa60807 ext/reflection: Align return types and values (#19567)
Return `true` or `false` for boolean functions, use `zend_result` for functions
that return `SUCCESS` or `FAILURE`.
2025-08-25 01:52:46 -07:00
Daniel Scherzer
63acc4bf61 [RFC] Add #[\DelayedTargetValidation] attribute (#18817)
https://wiki.php.net/rfc/delayedtargetvalidation_attribute
2025-08-20 00:41:20 -07:00
Máté Kocsis
1cff1815d0 Add internal URI handling API (#19073)
Part of https://github.com/php/php-src/pull/14461. Related to https://wiki.php.net/rfc/url_parsing_api.
2025-08-19 18:35:09 +02:00
Daniel Scherzer
57a88b216c [RFC] Deprecate ReflectionProperty::getDefaultValue() without default (#19457)
https://wiki.php.net/rfc/deprecations_php_8_5
2025-08-12 05:50:27 -07:00
Daniel Scherzer
ffdc1044c9 [RFC] Deprecate ReflectionClass::getConstant() for missing constants (#19456)
https://wiki.php.net/rfc/deprecations_php_8_5
2025-08-12 05:50:20 -07:00
Tim Düsterhus
922c225fbf reflection: Deprecate Reflection*::setAccessible() (#19273)
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_reflectionsetaccessible
2025-08-08 21:24:41 +01:00
Daniel Scherzer
63f9e4945d GH-17927: Indicate virtual properties and hooks in reflection output (#19297) 2025-07-31 17:32:09 -07:00
Daniel Scherzer
ff810d5e36 Arginfo: reuse zend_string objects for initializing attribute values (#19241)
Avoid initializing the same string content multiple times and make use of the
fact that the strings created to initialize attribute values are not freed by
simply making use of an existing zend_string with the same content if one is
available.
2025-07-27 17:27:22 -07:00
Daniel Scherzer
b428bc934a ext/reflection: voidify format_default_value() (#19234)
This function always returned SUCCESS unconditionally; removing the return type
revealed some impossible code for handling FAILURE that could also be removed.
2025-07-25 09:04:28 -07:00
Alexandre Daubois
d292968f7c Add ReflectionProperty::getMangledName() (#18980) 2025-07-22 12:24:27 -07:00
Ilija Tovilo
5a06842bf8 Fix '?' in ReflectionNamedType::getName() from ReflectionProperty::getSettableType()
Fixes GH-19187
Closes GH-19201
2025-07-22 15:57:15 +02:00
DanielEScherzer
1eadf553f1 Arginfo: avoid using temporary zvals for initializing attribute values (#19141)
Instead of
* adding a zval on the stack
* initializing it
* copying the value to the attribute

Just initialize the value directly in the zend_attribute_arg
2025-07-21 13:33:51 -07:00
Daniel Scherzer
142e378618 Arginfo: add and use known strings for attribute values 2025-07-14 17:31:22 -07:00
Tim Düsterhus
b43a7ac0e7 Zend: Make EG(fake_scope) a const zend_class_entry* (#19060) 2025-07-09 11:55:53 +02:00
DanielEScherzer
d43fbc0c0e ReflectionParameter::allowsNull() - fix typo in description [skip ci] 2025-07-04 12:33:48 -07:00
DanielEScherzer
171501b93f Replace @deprecated with #[\Deprecated] for internal constants (#18780)
Only covers constants declared via stub files, others will be handled
separately in a later commit.

Does not include the intl extension, since that had some errors relating to the
cpp code; that extension will be updated separately.
2025-06-26 11:27:15 -07:00
DanielEScherzer
4dfba7a250 [RFC] Final Property Promotion
https://wiki.php.net/rfc/final_promotion
2025-06-22 12:29:26 -07:00
DanielEScherzer
8f3cdf6236 gen_stub: Add support for attributes on constants in stubs (#18735)
Update to PHP-Parser 5.5.0 and add support for attributes on constants in
stubs. For now, I have only migrated over E_STRICT, once the support is in
place I'll do a larger migration of the existing deprecated constants.

In the process, fix the logic in `copy_zend_constant()` for copying attributes
when a constant is copied; just increase the reference count for the attributes
table rather than trying to duplicate the contents.
2025-06-05 14:46:46 -07:00
Marc Bennewitz
3a14ce19a5 Fix stubs of DateTimeZone->getTransitions (#17992)
The default value of `timestamp_end` is INT32_MAX and not ZEND_LONG_MAX
2025-06-03 22:42:05 -07:00
Tim Düsterhus
4c5a6b0e8d tree-wide: Remove stacktraces from tests testing throwing clones (#18748)
This is in preparation for the possible future transformation of `clone` into a
function call, but also meaningful on its own, since the purpose of the tests
is not to test the stack trace generation, but rather that an exception was
thrown. It also cleans up some unreachable code in the tests.
2025-06-03 20:08:47 +02:00
Niels Dossche
c7db07eae8 Remove duplicated reflection test
[ci skip]

This is already tested in 016.phpt.
2025-05-25 14:24:53 +02:00
Máté Kocsis
7f59fccd52 Create separate lexbor extension (#18538)
An always enabled lexbor extension is added, containing the lexbor library that was separated from ext/dom extension in preparation of https://wiki.php.net/rfc/url_parsing_api. While at it, the lexbor library is upgraded to 2.5.0.

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Co-authored-by: Gina Peter Banyard <girgias@php.net>
2025-05-25 14:12:44 +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
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
DanielEScherzer
ce3d1cd5cb Fix typo in ReflectionParameter::getName() description [skip ci] 2025-03-31 11:15:26 -07:00
DanielEScherzer
0006522211 Reflection: optimize smart_str building
- When appending a single character to the string, use `smart_str_appendc()`
- When appending a C-string without printf use, use `smart_str_appends()`
- When appending just a `zend_string`, use `smart_str_append()`
2025-03-26 16:00:34 -07:00
Daniel Scherzer
4233394e8f ReflectionClass: show enums differently from classes
While internally enums are mostly the same as classes, their output in
`ReflectionClass::__toString()` should show the enum as the developer wrote it,
rather than as the engine stored it. Accordingly

- Say that the enum is an enum, not a final class

- Include the backing type, if any, in the declaration line

- List enum cases separately from constants, and show the underlying values, if
any

GH-15766
2025-03-26 13:45:25 -07:00
Daniel Scherzer
6c81f708c5 ReflectionClass: test enum output
In preparation for improving it, GH-15766
2025-03-26 13:45:25 -07:00