Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:32358 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72218 invoked by uid 1010); 17 Sep 2007 12:23:43 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 72203 invoked from network); 17 Sep 2007 12:23:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Sep 2007 12:23:43 -0000 Authentication-Results: pb1.pair.com header.from=andrew@bramp.freeserve.co.uk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=andrew@bramp.freeserve.co.uk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain bramp.freeserve.co.uk from 212.159.14.134 cause and error) X-PHP-List-Original-Sender: andrew@bramp.freeserve.co.uk X-Host-Fingerprint: 212.159.14.134 pih-relay08.plus.net Linux 2.6 Received: from [212.159.14.134] ([212.159.14.134:54208] helo=pih-relay08.plus.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 54/71-62265-DC17EE64 for ; Mon, 17 Sep 2007 08:23:43 -0400 Received: from [80.229.232.206] (helo=Andrew) by pih-relay08.plus.net with smtp (Exim) id 1IXFda-0004dU-Sq for internals@lists.php.net; Mon, 17 Sep 2007 13:23:39 +0100 Message-ID: <00e001c7f925$4dd85d80$0a00a8c0@Andrew> To: References: <001f01c7f6f0$dbcf5350$4001a8c0@pc07653> Date: Mon, 17 Sep 2007 13:21:41 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="Windows-1252"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 Subject: Re: [PHP-DEV] RFC: mark functions as const for possible optimizations From: andrew@bramp.freeserve.co.uk ("Andrew Brampton") From: "Nuno Lopes" To: "PHPdev" Cc: ; ; > 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