Commit graph

1044 commits

Author SHA1 Message Date
Daniel Scherzer
331da7e869
Fix GH-16187: ReflectionClass::__toString() with packed properties hash table
Closes GH-16192.
2024-10-05 10:18:11 +02:00
Ilija Tovilo
f8d1864bbb
Delay #[Attribute] arg validation until runtime
Fixes GH-13970
Closes GH-14105

We cannot validate at compile-time for multiple reasons:

* Evaluating the argument naively with zend_get_attribute_value can lead to code
  execution at compile time through the new expression, leading to possible
  reentrance of the compiler.
* Even if the evaluation was possible, it would need to be restricted to the
  current file, because constant values coming from other files can change
  without affecting the current compilation unit. For this reason, validation
  would need to be repeated at runtime anyway.
* Enums cannot be instantiated at compile-time (the actual bug report). This
  could be allowed here, because the value is immediately destroyed. But given
  the other issues, this won't be needed.

Instead, we just move it to runtime entirely. It's only needed for
ReflectionAttribute::newInstance(), which is not particularly a hot path. The
checks are also simple.
2024-05-06 12:38:56 +02:00
Ilija Tovilo
9437aa9a8e
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix segfault in format_default_value due to unexpected enum/object
2023-08-17 18:43:49 +02:00
Ilija Tovilo
f78d1d0d10
Fix segfault in format_default_value due to unexpected enum/object
Evaluating constants at comptime can result in arrays that contain objects. This
is problematic for printing the default value of constant ASTs containing
objects, because we don't actually know what the constructor arguments were.
Avoid this by not propagating array constants.

Fixes GH-11937
Closes GH-11947
2023-08-17 18:43:11 +02:00
Niels Dossche
832a3d193f Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10914: OPCache with Enum and Callback functions results in segmentation fault
2023-07-11 17:40:21 +02:00
Niels Dossche
bc42179133 Fix GH-10914: OPCache with Enum and Callback functions results in segmentation fault
See linked issue for analysis.

Closes GH-11675.
2023-07-11 17:38:09 +02:00
Niels Dossche
dd29b66dfa Fix GH-10983: State-dependant segfault in ReflectionObject::getProperties
This is a variant of GH-10200, but in a different place.
Basically, simplexml may create a properties table that's packed instead
of associative. But the macro that was used to loop over the properties
table assumed that it was always associative. Replace it by the macro
that figures it out automatically which one of the two it is.

For test: Co-authored-by: jnvsor

Closes GH-10984.
2023-04-01 20:19:14 +02:00
Remi Collet
420469bd25
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  remove assert raising strange behavior with GCC 10
2023-03-15 09:06:05 +01:00
Remi Collet
bdf2f722ca
remove assert raising strange behavior with GCC 10 2023-03-15 09:05:44 +01:00
Ilija Tovilo
f1818d726f
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix segfault when using ReflectionFiber (fixes #10439)
2023-02-23 23:27:55 +01:00
Daniil Gentili
8d1c0a1403
Fix segfault when using ReflectionFiber (fixes #10439)
Closes GH-10478
2023-02-23 23:20:27 +01:00
David Carlier
2f4ba1b1fb Merge branch 'PHP-8.1' into PHP-8.2 2023-02-19 20:30:59 +00:00
Niels Dossche
ae16471628 Fix GH-10623: ReflectionFunction::getClosureUsedVariables() returns empty array in presence of variadic arguments
The code was missing the handling for the RECV_VARIADIC instruction.
Additional regression test for GH-10623

Co-authored-by: Fabio Ivona <fabio.ivona@defstudio.it>
2023-02-19 20:18:28 +00:00
Bob Weinand
a01dd9feda Revert "Port all internally used classes to use default_object_handlers"
This reverts commit 94ee4f9834.

The commit was a bit too late to be included in PHP 8.2 RC1. Given it's a massive ABI break, we decide to postpone the change to PHP 8.3.
2022-09-14 11:13:23 +02:00
Ilija Tovilo
a85c757dcb
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Private method incorrectly marked as "overwrites" in reflection
2022-09-08 10:44:32 +02:00
Ilija Tovilo
a795f3ebc6
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Private method incorrectly marked as "overwrites" in reflection
2022-09-08 10:44:13 +02:00
Ilija Tovilo
1435fc6262
Private method incorrectly marked as "overwrites" in reflection
Fix GH-9409
Closes GH-9469
2022-09-08 10:43:25 +02:00
Arnaud Le Blanc
dcde9b85a6 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] NEWS
  [ci skip] NEWS
  Add tests
  Fix GH-8932: Provide a way to get the called-scope of closures (#9299)
2022-09-02 13:55:57 +02:00
Arnaud Le Blanc
409baac29c Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  [ci skip] NEWS
  Add tests
  Fix GH-8932: Provide a way to get the called-scope of closures (#9299)
2022-09-02 13:53:14 +02:00
Nicolas Grekas
93f11d8429
Fix GH-8932: Provide a way to get the called-scope of closures (#9299)
Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
2022-09-02 13:32:50 +02:00
Bob Weinand
94ee4f9834 Port all internally used classes to use default_object_handlers
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-31 16:45:27 +02:00
Ilija Tovilo
2152bb2dfa
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix attribute target validation on fake closures
2022-07-29 12:15:38 +02:00
Ilija Tovilo
565a416e87
Fix attribute target validation on fake closures
Fixes GH-8982
Closes GH-9173
2022-07-29 12:14:44 +02:00
Máté Kocsis
e4d79ce24c
Declare ext/reflection constants in stubs (#9111) 2022-07-23 12:59:30 +02:00
Go Kudo
4d8dd8d258
Implement Random Extension
https://wiki.php.net/rfc/rng_extension
https://wiki.php.net/rfc/random_extension_improvement
2022-07-19 10:27:38 +01:00
Dmitry Stogov
c6eb5dc5fd Fix possible crash in case of exception
Fixes oss-fuzz #49068
2022-07-18 15:40:11 +03:00
Pierrick Charron
4dd66b8ce0
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed bug GH-8943 Reflection::getModifiersNames() with readonly modifier
2022-07-07 17:03:25 -04:00
Pierrick Charron
c650e67c90
Fixed bug GH-8943 Reflection::getModifiersNames() with readonly modifier 2022-07-07 16:59:54 -04:00
George Peter Banyard
0ae6a67550
Add true as a type (#8326)
RFC: https://wiki.php.net/rfc/true-type
2022-06-12 23:28:19 +01:00
Ilija Tovilo
ddc0b490f7
Allow arbitrary const expressions in backed enums
Closes GH-7821
Closes GH-8190
Closes GH-8418
2022-06-12 22:56:05 +02:00
George Peter Banyard
b40ae80804
Convert iterable into an internal alias for Traversable|array (#7309)
This does a compile time transformation of ``iterable`` into ``Traversable|array`` which simplifies some of the LSP variance handling.

The arginfo generation script from stubs is updated to produce a union type when it encounters the type ``iterable``
Extension functions which do not regenerate the arginfo, or write them manually are still supported by mimicking the compile time transformation while registering the function.

Type Reflection is preserved for single ``iterable`` (and ``?iterable``) to produce a ReflectionNamedType with name ``iterable``, however usage of ``iterable`` in union types will be converted to ``array|Traversable``
2022-06-07 13:35:34 +01:00
Dmitry Stogov
7451b8b6b0 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix memory leak
2022-06-06 11:38:37 +03:00
Dmitry Stogov
74744f3c0d Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix memory leak
2022-06-06 11:38:29 +03:00
Dmitry Stogov
088e5677fb Fix memory leak
This fixes oss-fuzz #47791
2022-06-06 11:35:01 +03:00
Máté Kocsis
7850c10389
Add support for readonly classes (#7305)
RFC: https://wiki.php.net/rfc/readonly_classes
2022-05-16 20:40:23 +02:00
Ollie Read
f590782b60
Add ReflectionMethod::hasPrototype method
Closes GH-8487.
2022-05-09 16:48:54 +02:00
Nicolas Grekas
be11bcb0b1
Add ReflectionFunction::isAnonymous()
Closes GH-8499.
2022-05-09 12:56:10 +02:00
Máté Kocsis
fc04a6ebdd
Throw when calling ReflectionAttribute::__construct()
ReflectionAttribute::__construct() accepted any number of parameters until now, because parameter validation was missing. Even though this was unlikely to be an issue in practice (since the method is private), the problem is fixed by always throwing an exception.
2022-05-03 21:23:22 +02:00
Máté Kocsis
ef5478b823
Reorder param parsing and reflection object retrieval 2022-05-03 20:34:00 +02:00
Ilija Tovilo
90a845c13f
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix ReflectionProperty::__toString() of properties containing enums
2022-04-29 10:22:08 +02:00
Ilija Tovilo
1944c14ce7
Fix ReflectionProperty::__toString() of properties containing enums
Fix GH-8444
2022-04-28 19:48:23 +02:00
Ilija Tovilo
91fe8075ab
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8421: Attributes that target functions are not valid for anonymous functions defined within a method
2022-04-23 11:19:34 +02:00
Ilija Tovilo
82d3a831d2
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8421: Attributes that target functions are not valid for anonymous functions defined within a method
2022-04-23 11:19:20 +02:00
Ollie Read
d0f1b987a5
Fix GH-8421: Attributes that target functions are not valid for anonymous functions defined within a method
Closes GH-8424
2022-04-23 11:16:28 +02:00
George Peter Banyard
6039c07a3a
Allow `null and false` as standalone types (#7546)
RFC: https://wiki.php.net/rfc/null-standalone-type

Also a drive-by consistency fix for error messages.
2022-04-08 17:23:52 +01:00
Christoph M. Becker
c8720568ec
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8080: ReflectionClass::getConstants() depends on def. order
2022-02-28 10:12:23 +01:00
Christoph M. Becker
27d2fddf6a
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8080: ReflectionClass::getConstants() depends on def. order
2022-02-28 10:11:29 +01:00
Christoph M. Becker
0d266a24d6
Fix GH-8080: ReflectionClass::getConstants() depends on def. order
When we need to evaluate constant ASTs, we always have to do that in
the scope where the constant has been defined, which may be a parent
of the `ReflectionClass`'s scope.

Closes GH-8106.
2022-02-28 10:08:47 +01:00
Dmitry Stogov
9a165336bd Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix ext/zend_test/tests/observer_bug81430_2.phpt failure
2022-01-12 12:10:23 +03:00
Dmitry Stogov
f6d7f78a9b Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix ext/zend_test/tests/observer_bug81430_2.phpt failure
2022-01-12 12:09:28 +03:00