Download src/php/php-src/Zend/tests/attributes/005_objects.phpt from meddyrat/dis-bench: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/datasets/meddyrat/dis-bench/resolve/main/src/php/php-src/Zend/tests/attributes/005_objects.phpt
- Command line
-
hf download hf://datasets/meddyrat/dis-bench/src/php/php-src/Zend/tests/attributes/005_objects.phpt
-
curl -L -o 005_objects.phpt https://huggingface.co/datasets/meddyrat/dis-bench/resolve/main/src/php/php-src/Zend/tests/attributes/005_objects.phpt
2.13 kB
| --TEST-- | |
| Attributes can be converted into objects. | |
| --FILE-- | |
| (Attribute::TARGET_FUNCTION) | |
| class A1 | |
| { | |
| public string $name; | |
| public int $ttl; | |
| public function __construct(string $name, int $ttl = 50) | |
| { | |
| $this->name = $name; | |
| $this->ttl = $ttl; | |
| } | |
| } | |
| $ref = new \ReflectionFunction(('test') function () { }); | |
| foreach ($ref->getAttributes() as $attr) { | |
| $obj = $attr->newInstance(); | |
| var_dump(get_class($obj), $obj->name, $obj->ttl); | |
| } | |
| echo "\n"; | |
| $ref = new \ReflectionFunction( function () { }); | |
| try { | |
| $ref->getAttributes()[0]->newInstance(); | |
| } catch (\ArgumentCountError $e) { | |
| var_dump('ERROR 1', $e->getMessage()); | |
| } | |
| echo "\n"; | |
| $ref = new \ReflectionFunction(([]) function () { }); | |
| try { | |
| $ref->getAttributes()[0]->newInstance(); | |
| } catch (\TypeError $e) { | |
| var_dump('ERROR 2', $e->getMessage()); | |
| } | |
| echo "\n"; | |
| $ref = new \ReflectionFunction( function () { }); | |
| try { | |
| $ref->getAttributes()[0]->newInstance(); | |
| } catch (\Error $e) { | |
| var_dump('ERROR 3', $e->getMessage()); | |
| } | |
| echo "\n"; | |
| class A3 | |
| { | |
| private function __construct() { } | |
| } | |
| $ref = new \ReflectionFunction( function () { }); | |
| try { | |
| $ref->getAttributes()[0]->newInstance(); | |
| } catch (\Error $e) { | |
| var_dump('ERROR 4', $e->getMessage()); | |
| } | |
| echo "\n"; | |
| class A5 { } | |
| $ref = new \ReflectionFunction( function () { }); | |
| try { | |
| $ref->getAttributes()[0]->newInstance(); | |
| } catch (\Error $e) { | |
| var_dump('ERROR 6', $e->getMessage()); | |
| } | |
| --EXPECTF-- | |
| string(2) "A1" | |
| string(4) "test" | |
| int(50) | |
| string(7) "ERROR 1" | |
| string(%d) "Too few arguments to function A1::__construct(), 0 passed in %s005_objects.php on line 26 and at least 1 expected" | |
| string(7) "ERROR 2" | |
| string(%d) "A1::__construct(): Argument #1 ($name) must be of type string, array given, called in %s005_objects.php on line 36" | |
| string(7) "ERROR 3" | |
| string(30) "Attribute class "A2" not found" | |
| string(7) "ERROR 4" | |
| string(51) "Call to private A3::__construct() from global scope" | |
| string(7) "ERROR 6" | |
| string(55) "Attempting to use non-attribute class "A5" as attribute" | |