Skip to content

Add #[\DelayedTargetValidation] attribute #18817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
--TEST--
#[\DelayedTargetValidation] affects errors from validators
--FILE--
<?php

#[DelayedTargetValidation]
#[AllowDynamicProperties]
trait DemoTrait {}

#[DelayedTargetValidation]
#[AllowDynamicProperties]
interface DemoInterface {}

#[DelayedTargetValidation]
#[AllowDynamicProperties]
readonly class DemoReadonly {}

#[DelayedTargetValidation]
#[AllowDynamicProperties]
enum DemoEnum {}

$cases = [
new ReflectionClass('DemoTrait'),
new ReflectionClass('DemoInterface'),
new ReflectionClass('DemoReadonly'),
new ReflectionClass('DemoEnum'),
];
foreach ($cases as $r) {
echo str_repeat("*", 20) . "\n";
echo $r . "\n";
$attributes = $r->getAttributes();
var_dump($attributes);
try {
$attributes[1]->newInstance();
} catch (Error $e) {
echo get_class($e) . ": " . $e->getMessage() . "\n";
}
}

?>
--EXPECTF--
********************
Trait [ <user> trait DemoTrait ] {
@@ %s %d-%d

- Constants [0] {
}

- Static properties [0] {
}

- Static methods [0] {
}

- Properties [0] {
}

- Methods [0] {
}
}

array(2) {
[0]=>
object(ReflectionAttribute)#%d (1) {
["name"]=>
string(23) "DelayedTargetValidation"
}
[1]=>
object(ReflectionAttribute)#%d (1) {
["name"]=>
string(22) "AllowDynamicProperties"
}
}
Error: Cannot apply #[AllowDynamicProperties] to trait DemoTrait
********************
Interface [ <user> interface DemoInterface ] {
@@ %s %d-%d

- Constants [0] {
}

- Static properties [0] {
}

- Static methods [0] {
}

- Properties [0] {
}

- Methods [0] {
}
}

array(2) {
[0]=>
object(ReflectionAttribute)#%d (1) {
["name"]=>
string(23) "DelayedTargetValidation"
}
[1]=>
object(ReflectionAttribute)#%d (1) {
["name"]=>
string(22) "AllowDynamicProperties"
}
}
Error: Cannot apply #[AllowDynamicProperties] to interface DemoInterface
********************
Class [ <user> readonly class DemoReadonly ] {
@@ %s %d-%d

- Constants [0] {
}

- Static properties [0] {
}

- Static methods [0] {
}

- Properties [0] {
}

- Methods [0] {
}
}

array(2) {
[0]=>
object(ReflectionAttribute)#%d (1) {
["name"]=>
string(23) "DelayedTargetValidation"
}
[1]=>
object(ReflectionAttribute)#%d (1) {
["name"]=>
string(22) "AllowDynamicProperties"
}
}
Error: Cannot apply #[AllowDynamicProperties] to readonly class DemoReadonly
********************
Enum [ <user> enum DemoEnum implements UnitEnum ] {
@@ %s %d-%d

- Constants [0] {
}

- Static properties [0] {
}

- Static methods [1] {
Method [ <internal, prototype UnitEnum> static public method cases ] {

- Parameters [0] {
}
- Return [ array ]
}
}

- Properties [1] {
Property [ public protected(set) readonly string $name ]
}

- Methods [0] {
}
}

array(2) {
[0]=>
object(ReflectionAttribute)#%d (1) {
["name"]=>
string(23) "DelayedTargetValidation"
}
[1]=>
object(ReflectionAttribute)#%d (1) {
["name"]=>
string(22) "AllowDynamicProperties"
}
}
Error: Cannot apply #[AllowDynamicProperties] to enum DemoEnum
Loading