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

1581 Commits

Author SHA1 Message Date
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
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
Tim Düsterhus
da1e254652 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix `ReflectionFunction::isDeprecated()` for materialized `__call()` (#17914)
2025-02-27 14:48:24 +01:00
Tim Düsterhus
2e999bad34 Fix ReflectionFunction::isDeprecated() for materialized __call() (#17914)
* Fix `ReflectionFunction::isDeprecated()` for materialized `__call()`

Fixes php/php-src#17913

* NEWS
2025-02-27 14:48:08 +01: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
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
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
Arnaud Le Blanc
a087442259 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix the name of the initializer parameter of ReflectionClass::resetAsLazyGhost()
2024-11-12 18:52:16 +01:00