Re: Annotations in PHP7

From: Date: Mon, 16 Feb 2015 12:40:18 +0000
Subject: Re: Annotations in PHP7
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-82836@lists.php.net to get a copy of this message
2015-02-16 15:31 GMT+03:00 Benjamin Eberlei <kontakt@beberlei.de>: > > My question is how do i evaluate this at runtime? I suppose a function is > necessary like evaluate_ast(...), but that requires passing the context. > many many open questions and as nikic points out this should probably be > delayed to 7.1 because it all should be discussed and specified. > This will be like pretty simple to parse: // For scalars: $attributes = (new ReflectionMethod(some::class, 'method))->getAttributes(); $cacheableNode = $attributes[Cacheable::class] ?? new Php\Parser\Node(AST_TYPE_VALUE, 50); $cacheTime = $cacheableNode->value; // For more complex things, like expressions or constant, runtime evaluation can be performed. $codeNode = $attributes[Php\Contract\Requires::class] ?? new Php\Parser\Node(AST_TYPE_STATEMENT, '$this->value >=0'); $code = (string) $codeNode; $result = eval($code);

« previous php.internals (#82836) next »