From: "Nuno Lopes" <[EMAIL PROTECTED]>
To: "PHPdev" <internals@lists.php.net>
Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>

My proposal is the following:
some functions when fed with constant arguments always return a constant value, too. e.g.:
strlen('abcd') === 4.

This means that an optimizer can and should do this transformation. (and others like: $a='abcd'; strlen($a); -> 4). I think Ilia created a list of such functions in his optimizer. But I would like to have that list in the core, so that everybody can benefit from it. Basically the only thing needed to do is to change PHP_FE() to PHP_CONST_FE() in the function entry tables.


I had a quick question about this. When would strlen('abcd') be execuated? Say I had the code:

$a = false; // This set by external input
if ( $a )
 $b = strlen('abcd');

Would the optimizer work out the length before the program starts to run? Or would the optimizer wait until it knows the strlen is going to be called then convert it to the constant 4?

I could see the optimizer "constifying" many function calls which will never get called.

thanks
Andrew
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to