Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68216 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53732 invoked from network); 19 Jul 2013 18:00:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2013 18:00:30 -0000 Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.211.66 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.211.66 config.schlueters.de Received: from [217.114.211.66] ([217.114.211.66:50349] helo=config.schlueters.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 62/FE-13120-CBE79E15 for ; Fri, 19 Jul 2013 14:00:29 -0400 Received: from [192.168.2.20] (ppp-188-174-56-141.dynamic.mnet-online.de [188.174.56.141]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by config.schlueters.de (Postfix) with ESMTPSA id 0ABD765DEA; Fri, 19 Jul 2013 20:00:26 +0200 (CEST) To: Daniel Lowrey Cc: "internals@lists.php.net" In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Date: Fri, 19 Jul 2013 20:00:06 +0200 Message-ID: <1374256806.3946.101.camel@guybrush> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Language constructs and callability From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) Hi, On Fri, 2013-07-19 at 12:36 -0400, Daniel Lowrey wrote: > I have a simple question about the callability of language constructs and > whether or not that's something that might change in the future. Consider: > > var_dump(is_callable('echo')); // bool(false) > var_dump(call_user_func('echo', 'foo')); // E_WARNING > echo('foo'); // foo > > var_dump(is_callable('isset')); // bool(false) > var_dump(isset(1)); // E_ERROR By itself the idea looks good and useful - but There is an issue: Those language constructs have different semantics from functions. On the one side there a simple difference which can more or less be ignored - like the fact that "echo" has no return value and might be called without parentheses. But also more complex ones: > var_dump(array_filter([0, FALSE, NULL], 'isset')); // [0, FALSE] The argument for isset is not sent via the regular parameter stack but directly as operands to the opcode. This is a key part to the trick on how it works for not producing a notice about undeclared variables and not creating it as userland emulations would. So let's assume we allow this then we must allow this simple code: $c = 'isset'; $c($foo); Now the opcode generated by the compiler here won't know what $c is in the second line (yes, yes, in this case an optimizer could figure it out) and will produce opcode which tries to fetch $foo on the argument stack. Now we could fix this in the executor by doing a string comparison on the function name and - oh wait - we'll already have messed with a variable which shouldn't be there ... So, unfortunately no, language constructs have different semantics which we can't emulate inside function semantics (well ok, it is software, so it is thinkable .. but nobody,yet, came up with a robust patch which doesn't cause maintenance *and* performance penalty) johannes