[php-src] Issue #7946: Rewrite zend_eval_const_expr to use a stack on the heap instead of recursion where possible?

From: Date: Sat, 15 Jan 2022 19:39:24 +0000
Subject: [php-src] Issue #7946: Rewrite zend_eval_const_expr to use a stack on the heap instead of recursion where possible?
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239026@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7946 Comment Author: TysonAndre >I don't think this makes sense. If it's just a matter of dealing with "x" . >"y" style cases, we can fold directly during parsing. If it's a matter of supporting >long $x . $y chains, then we should add a concat list node. I missed the first part about folding during parsing. zend_compile_create_balanced_binary_op_tree in that PR could be refactored to act on the unbalanced tree instead, with a loop, or concatenate directly Folding should probably also handle cases like return '$prefix . ' . var_export($value); where literals are mixed with non-literals (($prefix . 'literal') . 'literal2'), but opcache also optimizes consecutive concats, so that doesn't seem as urgent. For assert output, is there a need to keep the original AST? Also, assert seems to ignore operator precedence and not add parentheses. ``` php > assert("a" . '' == 123); Warning: assert(): assert('a' . '' == 123) failed in php shell code on line 1 php > assert('x='.PHP_VERSION == $var); Warning: assert(): assert('x=' . PHP_VERSION == $var) failed in php shell code on line 1 ``` Unrelatedly, assert isn't escaping null bytes in string literals ``` php > assert("\0" . '' == 123); Warning: assert(): assert(' failed in php shell code on line 1 ```

« previous php.bugs (#239026) next »