RE: Re: [PHP-DEV] constant folding optimization

From: Date: Mon, 10 Sep 2007 07:55:49 +0000
Subject: RE: Re: [PHP-DEV] constant folding optimization
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-32158@lists.php.net to get a copy of this message
I see a problem with this idea. In case we support constant expressions, we should support constants in such expressions, but the values of these constants may be unknown in compile time. <?php class Foo { const A = 0; } ?> <?php require_once "foo.php"; class Bar extends Foo { const B = self::A + 1; } ?> Delaying constant initialization for expressions in general will require keeping of Abstaract Syntax Tree, that should be evaluated at run-time by zval_update_constant(). Thanks. Dmitry. > -----Original Message----- > From: Nuno Lopes [mailto:nlopess@php.net] > Sent: Saturday, September 08, 2007 10:50 PM > To: Stanislav Malyshev > Cc: internals@lists.php.net; andi@php.net; dmitry@php.net > Subject: Re: Re: [PHP-DEV] constant folding optimization > > > >> I made a patch to implement constant folding optimization in the > >> Zend engine. > >> The patch is available at: > >> obî9F > >> "ëí7ŒYF™http://web.ist.utl.pt/nuno.lopes/zend_constant_folding.txt > > > > I like the idea a lot, however I think this patch has one > > significant downside - as far as I understand, it doesn't enable > > constant expressions in constant contexts. I.e. I can do $a = 2+2 > > and get it evaluated but I can't do function foo($a = 2+2) > or const > > $a = 2+2. If we moved this to the parser level I think we could do > > both. > > Well we don't support that syntax at this moment. If you are saying > that we could add support for such syntax.. it does seem a > good idea, > but in that case we would need to modify a few rules of the grammar > (like adding a const_expr production, and allow static_scalar derive > it, etc..). > > If others agree with this syntax, I can take a look in > implementing it. > > Nuno > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.internals (#32158) next »