Commit graph

1081 commits

Author SHA1 Message Date
Ilija Tovilo
780a8280d2
[RFC] Property hooks (#13455)
RFC: https://wiki.php.net/rfc/property-hooks

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2024-07-14 11:55:03 +02:00
Arnaud Le Blanc
11accb5cdf
Preferably include from build dir (#13516)
* Include from build dir first

This fixes out of tree builds by ensuring that configure artifacts are included
from the build dir.

Before, out of tree builds would preferably include files from the src dir, as
the include path was defined as follows (ignoring includes from ext/ and sapi/) :

    -I$(top_builddir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/main
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM
    -I$(top_builddir)/

As a result, an out of tree build would include configure artifacts such as
`main/php_config.h` from the src dir.

After this change, the include path is defined as follows:

    -I$(top_builddir)/main
    -I$(top_builddir)
    -I$(top_srcdir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM

* Fix extension include path for out of tree builds

* Include config.h with the brackets form

`#include "config.h"` searches in the directory containing the including-file
before any other include path. This can include the wrong config.h when building
out of tree and a config.h exists in the source tree.

Using `#include <config.h>` uses exclusively the include path, and gives
priority to the build dir.
2024-06-26 00:26:43 +02:00
Ilija Tovilo
998bce117c
Show enum cases in errors
Closes GH-14496
2024-06-10 22:58:25 +02:00
Tim Düsterhus
8a87206211
reflection: Add ReflectionGenerator::isClosed() (#14358)
* reflection: Add `ReflectionGenerator::isClosed()`

see https://github.com/php/php-src/pull/14167#issuecomment-2133641998

* Fix test expectation

* Drop `{{{` / `}}}` comments around `ReflectionGenerator::isClosed()`
2024-05-29 19:07:09 +02:00
Tim Düsterhus
8094bd1b58
Make ReflectionGenerator::getFunction() legal after generator termination (#14167)
* Make `ReflectionGenerator::getFunction()` legal after generator termination

* Expose the generator function name via `Generator::__debugInfo()`

* Allow creating `ReflectionGenerator` after termination

* Reorder `struct _zend_generator` to avoid a hole

* Adjust `ext/reflection/tests/028.phpt`

This is legal now.

* Fix Generator Closure collection

* Add test to verify the Closure dies with the generator

* NEWS / UPGRADING
2024-05-21 08:54:51 +02:00
Tim Düsterhus
c90c4fe553
Add zend_get_attribute_object() (#14161)
* Add `zend_get_attribute_object()`

This makes the implementation for `ReflectionAttribute::newInstance()`
reusable.

* Add test for the stack trace behavior of ReflectionAttribute::newInstance()

This test ensures that the `filename` parameter for the fake stack frame is
functional. Without it, the stack trace would show `[internal function]` for
frame `#0`.

* Fix return type of `call_attribute_constructor`
2024-05-14 08:39:43 +02:00
Ilija Tovilo
2ba30f0299
Merge branch 'PHP-8.3'
* PHP-8.3:
  Delay #[Attribute] arg validation until runtime
2024-05-06 12:48:45 +02:00
Ilija Tovilo
480d08a70a
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Delay #[Attribute] arg validation until runtime
2024-05-06 12:48:32 +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
Tim Düsterhus
6e8b134023
reflection: Fix ReflectionFunction::getShortName() for first class callables (#14087)
Fix fixes an incorrect fix in php/php-src#14001.
2024-04-30 17:27:11 +02:00
Tim Düsterhus
b5ffac7f6a
Add ReflectionClassConstant::isDeprecated() (#14086)
This is in preparation for php/php-src#11293 and for consistency with
ReflectionConstant::isDeprecated() that was added in php/php-src#13669.
2024-04-30 17:26:27 +02:00
Tim Düsterhus
d03d436528
reflection: Fix ReflectionFunction::getShortName() for Closures (#14001)
see php/php-src#13550
2024-04-19 12:14:16 +02:00
Ilija Tovilo
e23440e5a6
Implement reflection constant
Fixes GH-13570
Closes GH-13669
2024-04-17 22:53:09 +02:00
Niels Dossche
700fbca58d
Change getThis() into ZEND_THIS where possible (#13641) 2024-03-08 22:19:06 +01:00
Máté Kocsis
f2e199e878
Implement "support doc comments for internal classes and functions" (#13266)
Fixes #13130
2024-02-25 08:41:31 +01:00
Máté Kocsis
4b405d8520
Display class constant and property doc comments via reflection (#13499) 2024-02-25 08:39:41 +01:00
Niels Dossche
3b5986db69 Implement GH-12908: Show attribute name/class in ReflectionAttribute dump
This is consistent with how many other Reflection classes have a name
field, and it makes debugging easier.

Closes GH-12908.
Closes GH-12917.
2024-02-04 23:02:02 +01:00
Tim Düsterhus
97b3b4552d
random: Move CSPRNG API into php_random_csprng.h (#13290)
This allows consumers of just the CSPRNG to include a much smaller header. It
also allows to verify at a glance whether a source file might use non-secure
randomness.

This commit includes the new header wherever the CSPRNG is used, possibly
replacing the inclusion of php_random.h if nothing else is used, but also
includes it in the main php_random.h header for compatibility.

Somewhat related to 45f8cfaf10,
2b30f18708, and
b14dd85dca.
2024-02-01 19:09:35 +01:00
Máté Kocsis
688c6f373c Deprecate calling ReflectionMethod::__construct() with 1 argument 2023-12-04 22:27:59 +01:00
Ilija Tovilo
3433dab5f7
Revert 479e659331
There were 4 different reports of this breaking behavior. This is higher than I
expected. This bug fix may still be desirable, but should be discussed on the
list beforehand.

Closes GH-12127
2023-09-05 16:14:28 +02:00
Ilija Tovilo
48ede64506
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix segfault in format_default_value due to unexpected enum/object
2023-08-17 18:44:37 +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
Máté Kocsis
d9a7f6741e Deprecate ReflectionProperty::setValue() with an incorrect 1st arg type 2023-07-18 12:59:21 +02:00
Máté Kocsis
f41220fe5d Implement ReflectionMethod::createFromMethodName() 2023-07-18 12:59:21 +02:00
Ilija Tovilo
1a0ef2c1cc
Revert "Remove name field from the zend_constant struct (#10954)"
This reverts commit f42992f580.

Closes GH-11604
2023-07-17 22:32:41 +02:00
Niels Dossche
62a940880e Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-10914: OPCache with Enum and Callback functions results in segmentation fault
2023-07-11 17:44:37 +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
Ilija Tovilo
ad1b70d67e
Revert "Revert "Remove name field from the zend_constant struct (#10954)""
This reverts commit 9f4bd3040d.
2023-07-04 16:42:40 +02:00
Máté Kocsis
9f4bd3040d
Revert "Remove name field from the zend_constant struct (#10954)"
This reverts commit f42992f580.

Fix GH-11423
2023-07-03 15:16:24 +02:00
George Peter Banyard
d5ad75108e
More usage of known zend_str instead of C string (#11381) 2023-06-08 13:03:29 +01:00
Ilija Tovilo
0b1d750d91
Allow arbitrary expressions in static variable initializer
Closes GH-9301
2023-05-24 20:17:31 +02:00
Máté Kocsis
414f71a902
Typed class constants (#10444)
RFC: https://wiki.php.net/rfc/typed_class_constants

Co-Authored-By: Ben <7127204+moliata@users.noreply.github.com>
Co-Authored-By: Bob Weinand <3154871+bwoebi@users.noreply.github.com>
Co-Authored-By: Ilija Tovilo <ilija.tovilo@me.com>
2023-04-16 22:20:26 +02:00
Máté Kocsis
f42992f580
Remove name field from the zend_constant struct (#10954)
As global constant names are case-sensitive now, we don't have to store them separately above the constant table.
2023-04-03 22:13:47 +02:00
Niels Dossche
3ab6e76ed8 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-10983: State-dependant segfault in ReflectionObject::getProperties
  Fix GH-10990: mail() throws TypeError after iterating over $additional_headers array by reference
  Fix GH-8841: php-cli core dump calling a badly formed function
2023-04-01 20:23:57 +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
dd109926ed
Merge branch 'PHP-8.2'
* PHP-8.2:
  remove assert raising strange behavior with GCC 10
2023-03-15 09:06:29 +01: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
ab99072608
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix segfault when using ReflectionFiber (fixes #10439)
2023-02-23 23:28:31 +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
33f8d67177 Merge branch 'PHP-8.2' 2023-02-19 20:31:53 +00: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
Michael Voříšek
a11e9c9d02
Simplify php_reflection.c, class name cannot start with backslash (#10536)
* fix comment typo

* (normalized) class name never start with backslash
2023-02-11 14:50:25 +01:00
George Peter Banyard
50a2de78a8
Do not build unnecessary FCI in Reflection 2023-02-05 17:11:49 +00:00
Máté Kocsis
7936c8085e
Fix GH-8329 Print true/false instead of bool in error and debug messages (#8385) 2023-01-23 10:52:14 +01:00
Ilija Tovilo
e186765a4d
Throw in ReflectionMethod::__construct() when initialized with private parent method
Fixes GH-9470
Closes GH-9640
2022-10-10 00:49:10 +02:00