Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BogdanUngureanu/579ed6387e5c873fa2a3e9d4feb41da8 to your computer and use it in GitHub Desktop.
Save BogdanUngureanu/579ed6387e5c873fa2a3e9d4feb41da8 to your computer and use it in GitHub Desktop.
<?php
/// a built-in interface
interface TargetAttribute {
public function validate($target): boolean;
}
interface NonFooInterface {
}
<<PhpAttribute>>
class SingleArgument implements TargetAttribute {
public function __construct($argumentValue) {
}
public function validate(NonFooInterface $target): boolean {
return true; // you could add some complex logic here as well.
}
}
<<SingleArgument>> /// this would fail since the target, in this case Foo, doesn't implement the NonFooInterface
class Foo {
public __construct(string <<SingleArgument>> $prop) // this would also fail because it passes a string.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment