Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70275 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95453 invoked from network); 22 Nov 2013 04:35:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Nov 2013 04:35:00 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.171 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.220.171 mail-vc0-f171.google.com Received: from [209.85.220.171] ([209.85.220.171:41996] helo=mail-vc0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C1/30-28674-3FEDE825 for ; Thu, 21 Nov 2013 23:34:59 -0500 Received: by mail-vc0-f171.google.com with SMTP id ik5so508926vcb.30 for ; Thu, 21 Nov 2013 20:34:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Md9kU6YbdbnSw5s9SSeo7eIRm9R59Vt1S0o9SlyZnQo=; b=Isw9mURDiR4sH0cbLho2svqm74rPd7itgxksRAIa5zAhWHyP3ZLZn4tD62/px6WGjZ y1CLdMqdHPsSf5uldwMWAYWBZqyMBI/shUj6+BHMIMv82t7tSC7r63AW6EKkHAmEvxKr bILKg/1IMYP0e66W3DHrVc4CVRO2hK81Cgcw9zmczrug6HQRtKHrFALTzp3AxqtbQs9a swxJbrqfrVSUuzJ/YzPfJwUfUZhi4qMuox3cutBXRCZ0hy3g0snNyRYT9a7Gcd3V4c+b 0EL1ByD5PhCTd5LMOB74iQ8y7T+hmFvqZRzo537JE09sCJqZiXNF/DcppA1xzdzvrjHa gwfA== MIME-Version: 1.0 X-Received: by 10.220.86.69 with SMTP id r5mr9327668vcl.9.1385094896579; Thu, 21 Nov 2013 20:34:56 -0800 (PST) Received: by 10.58.128.33 with HTTP; Thu, 21 Nov 2013 20:34:56 -0800 (PST) In-Reply-To: References: Date: Fri, 22 Nov 2013 12:34:56 +0800 Message-ID: To: Yasuo Ohgaki Cc: Bob Weinand , List PHP Mailing List Content-Type: multipart/alternative; boundary=001a11c1ff444a783304ebbc891c Subject: Re: [PHP-DEV] [RFC] [VOTE] Constant scalar expressions From: tjerk.meesters@gmail.com (Tjerk Meesters) --001a11c1ff444a783304ebbc891c Content-Type: text/plain; charset=ISO-8859-1 Hi, On Fri, Nov 22, 2013 at 9:30 AM, Yasuo Ohgaki wrote: > Hi all, > > On Fri, Nov 22, 2013 at 10:19 AM, Yasuo Ohgaki wrote: > > > On Fri, Nov 22, 2013 at 10:09 AM, Yasuo Ohgaki > wrote: > > > >> Anyway, constant variables are useful for VM/op code optimization. > >> > >> include('foo.php'); // const a = 123; > >> const b = a; > >> > >> is allowed currently. We may restrict this behavior only to the same > file, > >> so that VM/op code optimization can be done. > >> > >> Currently, no expression is allowed with 'const'. Defining 'const' using > >> another constant with the same value is useless. It's a bad coding > >> practice > >> in many case, I suppose. > >> > >> I understand use cases of scalar expressions with constants, but I'm > >> concerned > >> loosing door for further optimizations. (e.g. $x = $x + 123 is faster > >> than $x = $x + a, > >> where a is 123 in constant var hash) > >> > >> We may be better to restrict expressions with constants only to the same > >> file > >> even if we loose some benefits/flexibility in user code. > >> > >> Is this discussed? > >> > > > > I voted 'yes', but I change my mind. Sorry. > > If the RFC leaves door for constant optimization, I'll vote 'yes'. > > Constant look up is not a simple hash look up. > > > > One more additional note why I decided to vote 'no' for this. > We already have dynamic constant via define(). > > define('A', 123); > define('B', A*2); > > echo B; // 246 > ?> > > We can even use function return values with define(). > > function foo() { > return 123; > } > > define('A', foo()); > > echo A; // 123 > ?> > Yes, of course that's all possible, because define() is just a function and therefore the normal assignment rules apply. However, you didn't mention the biggest drawback to such an approach, which is that it creates *global* constants; there's no way to namespace them. > I prefer 'const' to be a static for better performance, since > we have dynamic constant by define() already. > Perhaps we'd have to consider how much performance is impacted on existing code, e.g. class A { const B = 123; } How much slower would that become if this RFC is accepted, cached or otherwise? > > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > -- -- Tjerk --001a11c1ff444a783304ebbc891c--