[php-src] Issue #14747: Why are constant expressions decided at compile time instead of in the grammar?
| From: | chx | Date: | Mon, 01 Jul 2024 13:56:17 +0000 |
| Subject: | [php-src] Issue #14747: Why are constant expressions decided at compile time instead of in the grammar? | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247198@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/14747
Author: chx
### Description
I was looking at
zend_language_parser.y and I was surprised to see
attribute allows a full expr and there's no const_expr
definition. When I look at zend_is_allowed_in_const_expr on the other hand, it only
contains multiple comparisons to constants defined in the _zend_ast_kind enum. In turn,
it seems to me these are created in zend_language_parser.y using calls like
zend_ast_create(ZEND_AST_CLASS_CONST, $1, $4); That means it should be possible to
simply take all the declarations which lead to such an zend_ast_create() calls for
every constant in zend_is_allowed_in_const_expr and thus define a
const_expr in the language parser instead of deciding whether an expression is constant
at compile time.
Mind you I never worked with yacc before so I might be totally wrong here, I am just reading the
source code. But if my observation is correct... why there isn't a const_expr?
Should I make an attempt in creating one :) ? Is there tooling which would help creating one such?
### PHP Version
PHP 8.3.8
### Operating System
_No response_