Commit Graph

18 Commits

Author SHA1 Message Date
Benjamin Eberlei
72c874691b
RFC: Add #[\Deprecated] Attribute (#11293)
see https://wiki.php.net/rfc/deprecated_attribute

Co-authored-by: Tim Düsterhus <tim@tideways-gmbh.com>
Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2024-07-02 09:44:25 +02:00
Ilija Tovilo
6335264c07
Fix header errors when parsed standalone (#14272)
This is annoying for multiple reasons:

1. LSPs can show many errors for these files.
2. LSP can stop parsing these files completely if there are too many errors,
   resulting in spotty LSP features.
2024-05-20 22:30:38 +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
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
49ef6e209d
RFC: Add #[Override] attribute (#9836)
* Add #[Override] attribute

* Move #[\Override] tests into Zend/tests/attributes/override/

* Check `check_only` before removing `ZEND_ACC_OVERRIDE`

* NEWS/UPGRADING for #[\Override]
2023-06-29 20:23:53 +02:00
Tim Düsterhus
342e18f105
Support the actual #[\SensitiveParameter] attribute in stubs (#8836) 2022-07-12 12:43:44 +02:00
Bob Weinand
9f29e2d7e9 Allow for arbitrary (class) attributes in stubs
This can be easily extended to other types of attributes.

Closes #8839.
2022-07-05 18:23:05 +02:00
Tim Düsterhus
49951165f0 Add zend_mark_function_parameter_as_sensitive() 2022-06-04 18:15:05 +02:00
Tim Düsterhus
9085197734
Implement the "Redacting parameters in back traces" RFC
https://wiki.php.net/rfc/redact_parameters_in_back_traces
2022-04-08 10:36:16 +02:00
Nikita Popov
902d64390e Deprecate implicit dynamic properties
Writing to a proprety that hasn't been declared is deprecated,
unless the class uses the #[AllowDynamicProperties] attribute or
defines __get()/__set().

RFC: https://wiki.php.net/rfc/deprecate_dynamic_properties
2021-11-26 14:10:11 +01:00
Nikita Popov
3e01f5afb1 Replace zend_bool uses with bool
We're starting to see a mix between uses of zend_bool and bool.
Replace all usages with the standard bool type everywhere.

Of course, zend_bool is retained as an alias.
2021-01-15 12:33:06 +01:00
Nikita Popov
5686c16db4 Honor strict_types=1 for attributes, improve backtraces
Make ReflectionAttribute::newInstance() respect the strict_types=1
declaration at the attribute use-site. More generally, pretend that
we are calling the attribute constructor from the place where the
attribute is used, which also means that the attribute location will
show up properly in backtraces and inside "called in" error information.

This requires us to store the attributes strict_types scope (as flags),
as well as the attribute line number. The attribute filename can be
recovered from the symbol it is used on. We might want to expose the
attribute line number via reflection as well.

See also https://externals.io/message/111915.

Closes GH-6201.
2020-09-27 10:42:58 +02:00
George Peter Banyard
fa8d9b1183 Improve type declarations for Zend APIs
Voidification of Zend API which always succeeded
Use bool argument types instead of int for boolean arguments
Use bool return type for functions which return true/false (1/0)
Use zend_result return type for functions which return SUCCESS/FAILURE as they don't follow normal boolean semantics

Closes GH-6002
2020-08-28 15:41:27 +02:00
Nikita Popov
d92229d8c7 Implement named parameters
From an engine perspective, named parameters mainly add three
concepts:

 * The SEND_* opcodes now accept a CONST op2, which is the
   argument name. For now, it is looked up by linear scan and
   runtime cached.
 * This may leave UNDEF arguments on the stack. To avoid having
   to deal with them in other places, a CHECK_UNDEF_ARGS opcode
   is used to either replace them with defaults, or error.
 * For variadic functions, EX(extra_named_params) are collected
   and need to be freed based on ZEND_CALL_HAS_EXTRA_NAMED_PARAMS.

RFC: https://wiki.php.net/rfc/named_params

Closes GH-5357.
2020-07-31 15:53:36 +02:00
Martin Schröder
053ef28b8d Implement Attribute Amendments.
RFC: https://wiki.php.net/rfc/attribute_amendments

Support for attribute grouping is left out, because the short
attribute syntax RFC will likely make it obsolete.

Closes GH-5751.
2020-06-29 10:45:51 +02:00
Nikita Popov
5b4c4bbe3b Free attribute validators on shutdown 2020-06-05 10:36:35 +02:00
Benjamin Eberlei
a7908c2d11 Add Attributes
Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
2020-06-04 18:19:49 +02:00