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

792 Commits

Author SHA1 Message Date
Ilia Alshanetsky
4561e92fa1 Fix ReflectionMethod::invoke() for first class callables (#21389)
* Fix ReflectionMethod::invoke() crash with internal closures

The closure identity check added in GH-21366 accessed op_array.opcodes
unconditionally, but internal closures (e.g. var_dump(...)) use
internal_function, not op_array. This caused undefined behavior when
comparing closures created via first-class callable syntax on internal
functions.

Check the function type first: compare op_array.opcodes for user
closures, compare the function pointer directly for internal closures.

* Fix internal closure comparison and expand test coverage

The previous comparison (orig_func == given_func) could never match for
internal closures since zend_get_closure_method_def() returns a pointer
to each closure's embedded copy. Compare function_name and scope instead.

Also handle the mixed user/internal type case explicitly.

Add tests for: userland first-class callables, cloned internal closures,
and cross-type (user vs internal) closure rejection.

* php_reflection: Simplify the Closure::__invoke() check

---------

Co-authored-by: Tim Düsterhus <tim@bastelstu.be>
2026-03-14 17:00:04 -07:00
Ilia Alshanetsky
53e31d5883 Fix GH-21362: ReflectionMethod::invoke() allows different Closures (#21366)
ReflectionMethod::invoke() (and invokeArgs()) for Closure::__invoke()
incorrectly accepted any Closure object, not just the one the
ReflectionMethod was created from. This happened because all Closures
share a single zend_ce_closure class entry, so the instanceof_function()
check always passed.

Fix: store the original Closure object in intern->obj during
ReflectionMethod construction, then compare object identity in
reflection_method_invoke() to reject different Closure instances.

Closes GH-21362
2026-03-07 17:19:33 -08:00
Ilija Tovilo
471ae15312 Fix incorrect zend_hash_find_ptr() on non-ptr in ReflectionProperty::isReadable() (GH-21339)
Fixes OSS-Fuzz #489355368
2026-03-04 12:55:58 +01:00
Ilija Tovilo
e4f727d61e Implement ReflectionProperty::is{Readable,Writable}()
RFC: https://wiki.php.net/rfc/isreadable-iswriteable

Fixes GH-15309
Fixes GH-16175
Closes GH-16209
2026-02-27 14:26:06 +01:00
Khaled Alam
0b4fbf2e70 ext/reflection: Add ReflectionConstant::inNamespace() method (#20902) 2026-02-16 21:28:32 -08:00
Gina Peter Banyard
542175ecfa ext/standard: mark ext/random as a required dependency (#21130)
As the shuffle() and array_rand() functions use part of the Random API
2026-02-05 16:09:54 +00: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
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
e025f2a148 reflection: Test ReflectionFunction::__toString() with bound variables (#20608) 2025-11-30 10:39:04 +01: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
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
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
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
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
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
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
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
Arnaud Le Blanc
a8151fc511 Fix the name of the initializer parameter of ReflectionClass::resetAsLazyGhost()
Closes GH-16758
2024-11-12 18:51:33 +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