Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78800 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10744 invoked from network); 6 Nov 2014 09:14:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Nov 2014 09:14:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.45 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 74.125.82.45 mail-wg0-f45.google.com Received: from [74.125.82.45] ([74.125.82.45:49835] helo=mail-wg0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7F/2F-28384-FEB3B545 for ; Thu, 06 Nov 2014 04:14:24 -0500 Received: by mail-wg0-f45.google.com with SMTP id x12so667105wgg.4 for ; Thu, 06 Nov 2014 01:14:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:to:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=JvgllGL0xV+Udj6M8reIqUIhJANI4S69DQEXOO2jdaw=; b=fefwu98VWduAnTklPQqhBdD3S1nRL2GIRYKJ3VpAlVQxdw7GzHEi/+Fv+njfR8cURm 0M4Jb/a2xC/FWSX8y/ME4x6OsPLxGBt/zm2DK8i14yCJgD4bdOOBpYFxEKv3JGK/iTqp tbrM4/uqCdSuG6aNGvu7Jii6kLh+/XAiBSs11B/Zp+YlmD5QP2pxn/9Yq1vcyKSureFI iaIXlEyAU1wU3iIOLLgnLNmWlZGY6PyLZFjGJv6vpqrHh9Aunluv4i3NxX5xZUn4WwJL 1ClwIi1kt1IsYUrxZWRPevcP4nl1iUOsw/H36xD/2M5e00ih9aF3iZWhH8KLDUfomeHf Ha3w== X-Received: by 10.180.206.14 with SMTP id lk14mr39196575wic.47.1415265260353; Thu, 06 Nov 2014 01:14:20 -0800 (PST) Received: from nikita-pc ([91.75.241.115]) by mx.google.com with ESMTPSA id s10sm1275479wjw.29.2014.11.06.01.14.18 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 06 Nov 2014 01:14:19 -0800 (PST) Content-Type: text/plain; charset=koi8-r; format=flowed; delsp=yes To: "PHP internals" , "Stas Malyshev" References: <545B3900.6070208@sugarcrm.com> Date: Thu, 06 Nov 2014 13:14:20 +0400 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: <545B3900.6070208@sugarcrm.com> User-Agent: Opera Mail/12.17 (Win32) Subject: Re: [PHP-DEV] Allow arbitrary expressions when using instanceof operator From: inefedor@gmail.com ("Nikita Nefedov") On Thu, 06 Nov 2014 13:01:52 +0400, Stas Malyshev wrote: > Hi! > >> What I want to implement is the ability to allow arbitrary expressions >> on >> the second operand, so instead of having to write something like this: > > I'm afraid there's a problem with this. Arbitrary expressions include > constants, right? So what this means: > > var_dump($foo instanceof Bar); > > is it checking $foo for being instance of class Bar (that's what is > happening now) or is it taking the value of the constant Bar (whatever > it is) - since constant is an expression - and using it as a class name > and then checking if $foo is an instance of that class? > > You could of course require the expression to always be enclosed in (), > but that produces weird syntax where some forms of instanceof work > without () and some only with (). Given that you can easily assign your > value to a variable, is it worth it? > > Also, you can always use is_a($foo, $bar->getClassName()). Hey Stas, You're right about parenthesis - they are required to use expressions. Basically when you're in parenthesis - it will only mean that it's an expression, otherwise it's a direct class reference. It could be worked around by creating a new class of expression (on parser level, say expr_not_single_const or anyting like that) that would match any expression except constant references, but that's too much I guess. Also one thing not mentioned in the initial letter - this will also allow you to use expressions for new operator in the same way: `new (str_replace('/', '\\', $classPath))()` - just an example. I would say that it's just not logical to have some operator that can accept dynamic (runtime-defined) value but not an expression.