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

1153 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
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
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
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
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
Daniel Scherzer
c34558d125 GH-19691: Add asymmetric visibility to Reflection::getModifierNames() (#19697) 2025-09-04 23:00:36 -07: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
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
Daniel Scherzer
63f9e4945d GH-17927: Indicate virtual properties and hooks in reflection output (#19297) 2025-07-31 17:32:09 -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
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
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
Ilija Tovilo
ded8af57c4 Merge branch 'PHP-8.4'
* PHP-8.4:
  Reflection: indicate final and abstract properties in string output
2025-02-25 12:22:00 +01:00
Daniel Scherzer
81f143e71f Reflection: indicate final and abstract properties in string output
Add "final" and "abstract" to the result of `_property_string()` when
outputting the string representation of a `ReflectionClass` or
`ReflectionProperty` instance

Closes GH-17827
2025-02-25 12:21:15 +01:00
Niels Dossche
7063b01aab Merge branch 'PHP-8.4'
* PHP-8.4:
  Reflection: show the type of object constants used as default properties
2025-02-21 09:39:02 +01:00
Niels Dossche
77847b02b9 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Reflection: show the type of object constants used as default properties
2025-02-21 09:36:01 +01:00
Daniel Scherzer
ca0414e64d Reflection: show the type of object constants used as default properties
When a property default is based on a global constant, show the type of the
default. Previously, `format_default_value()` assumed that non-scalar and
non-array defaults were always going to be `IS_CONSTANT_AST` pointers, and when
the AST expression had been evaluated and produced an object, depending on when
the `ReflectionClass` or `ReflectionProperty` instance had been created, the
default was shown as one of `callable` or `__CLASS__`.

Instead, if the default value is an object (`IS_OBJECT`), show the type of that
object.

Add test cases for both of the `callable` and `__CLASS__` cases to confirm that
they now properly show the type of the constant.

Closes GH-15902.
Closes GH-17781.
2025-02-21 09:32:10 +01:00
Arnaud Le Blanc
8af9042405 Use new ZPP and inline caches in ReflectionProperty::getValue() and variants (#17698)
Apply the following changes to ReflectionProperty::getValue(), ::getRawValue(), ::isInitialized(), ::setValue(), ::setRawValue():

- Pass a cache slot to the property handler
- Inline the simple case of fetching a declared property
- Use the new parameter parsing API

This results in run time decrease of 12% to 59% in [micro benchmarks](https://gist.github.com/arnaud-lb/2de08142dcd0c7b49caed21398f44656), when executed with `hyperfine -L version base,opt "/tmp/{version}/sapi/cli/php -d opcache.enable_cli=1 $script"`:

```
get-raw-value.php:   -58%
get-value-dyn.php:   -50%
get-value-hook.php:  -47%
get-value.php:       -59%
is-initialized.php:  -59%
set-value.php:       -11%
```

And a 1.8% decrease in this Doctrine benchmark: 505825290d...reflection-property-get-value-opt
2025-02-17 13:46:59 +01:00
DanielEScherzer
07e5f6fc3d ReflectionClass::isCloneable(): reduce duplication (GH-17795)
When the `zend_class_entry` has a `zend_function` entry for `clone`, the logic
is the same regardless of if the `reflection_object` entry has an object or
not; the determination is based solely on the flags of the `zend_function`.
2025-02-14 16:50:33 +01:00
Gina Peter Banyard
65d433161a Use new known "self" and "parent" zend_strings (#17766) 2025-02-12 15:30:55 +00:00
Arnaud Le Blanc
763865320b Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix ReflectionProperty::getRawValue() and related methods for properties overridden with hooks
2025-02-07 10:49:40 +01:00
Arnaud Le Blanc
24b191a4de Fix ReflectionProperty::getRawValue() and related methods for properties overridden with hooks
`new Reflectionproperty($scope, $propName)` keeps a reference to the
zend_property_info of $propName declared in $scope. In getRawValue() and
related methods, we use this reference to check whether the property is hooked.

Calling `new ReflectionProperty($scope, $propName)->getRawValue($object)` is
equivalent to the expression $object->$propName from scope $scope (except that
it bypasses hooks), and thus may access an overridden property (unless the
original is private). This property may have hooks and different flags.

Here I fetch the effective property info before checking for hooks and
property flags.

Fixes GH-17713
Closes GH-17714
2025-02-07 10:49:02 +01:00
Niels Dossche
6e84c41d05 Fix GH-12856: ReflectionClass::getStaticPropertyValue() returns UNDEF zval for uninitialized typed properties
Closes GH-17590.
2025-01-30 19:22:59 +01:00
Arnaud Le Blanc
ea39c2709f Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix setRawValueWithoutLazyInitialization() and skipLazyInitialization() on initialized proxy
2024-11-26 14:07:32 +01:00
Arnaud Le Blanc
c310be09ed Fix setRawValueWithoutLazyInitialization() and skipLazyInitialization() on initialized proxy
Normally, accesses to properties marked as lazy trigger the object's
initialization, or forward to a real instance if the object is an initialized
proxy.

The purpose of ReflectionProperty::setRawValueWithoutLazyInitialization() and
ReflectionProperty::skipLazyInitialization() is to bypass auto-initialization,
so that some properties can be initialized without triggering initialization.

However, when the object is an initialized proxy, these methods would
unexpectedly update the proxy.

Here I make sure that these methods have an effect on the real instance, when
the object is an initialized proxy.

Fixes GH-16344
2024-11-26 14:04:58 +01:00
DanielEScherzer
62e53e6f49 Inline and remove reflection_instantiate() (#16739)
Since the return value is never used, the only difference between using this
method and using `object_init_ex()` directly is the flipped order of
parameters, and the added level of indirection - remove that level of
indirection by replacing its uses.
2024-11-09 17:40:45 +01:00
DanielEScherzer
54003aecc4 Fix description of ReflectionParameter::getPosition() (GH-16738)
Appears to have been copied from `ReflectionParameter::isOptional()`.

[skip ci]
2024-11-09 15:32:53 +01:00
DanielEScherzer
10f1f924cf Add ReflectionConstant::getExtension() and ::getExtensionName() (#16603) 2024-11-09 11:08:02 +01:00
Niels Dossche
64f2d11e38 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-16628: FPM logs are getting corrupted with this log statement
  Fix GH-16601: Memory leak in Reflection constructors
2024-11-02 19:39:00 +01:00
Niels Dossche
bfd9e0cca3 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16628: FPM logs are getting corrupted with this log statement
  Fix GH-16601: Memory leak in Reflection constructors
2024-11-02 19:38:54 +01:00
Niels Dossche
16cda10650 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16628: FPM logs are getting corrupted with this log statement
  Fix GH-16601: Memory leak in Reflection constructors
2024-11-02 19:37:28 +01:00
Niels Dossche
f0f666ba3f Fix GH-16601: Memory leak in Reflection constructors
Additionally fixes wrong behaviour in ReflectionParameter when you first
have a construction that uses an object and the subsequent doesn't.

Closes GH-16672.
2024-11-02 19:35:20 +01:00
Daniel Scherzer
f5e743a520 Add ReflectionConstant::getFileName()
Allow determining the name of the file that defined a constant, when the
constant was defined in userland code via const or define(). For constants
defined by PHP core or extensions, false is returned, matching the existing
getFileName() methods on other reflection classes.

Fixes GH-15723
Closes GH-15847
2024-10-31 16:47:45 +01:00
Arnaud Le Blanc
50a3f019dc Merge branch 'PHP-8.4'
* PHP-8.4:
  Add ReflectionProperty::isLazy()
2024-10-31 14:15:49 +01:00