Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86600 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 649 invoked from network); 11 Jun 2015 20:22:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jun 2015 20:22:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=are.you.winning@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=are.you.winning@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.65 as permitted sender) X-PHP-List-Original-Sender: are.you.winning@gmail.com X-Host-Fingerprint: 74.125.82.65 mail-wg0-f65.google.com Received: from [74.125.82.65] ([74.125.82.65:33609] helo=mail-wg0-f65.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E6/50-31453-1FDE9755 for ; Thu, 11 Jun 2015 16:22:09 -0400 Received: by wggy19 with SMTP id y19so4401770wgg.0 for ; Thu, 11 Jun 2015 13:22:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=1tTKsNcOXYZ/p4G6KtRbeky1M8zdJmDImXVla0ECYIQ=; b=vXSc/sA2hqP501405pOAgB9YaAlVgcu8EPsw1ZKJjJmXvh1qjXWa2b9Bw5ACdm0Aeb 7TKTza/uRwwWMic5p26FzLBUkWgFtm3VMBLrnRx9rkw4cyQZgTeZ5/TWfQim9KYsbHc1 4sjwl2k3NDMsq29ziUJssVCwDBe4SbaRlfybnvr0Png9559+LbWYGyoDpz1iC5wREWWX 0qbFxL0MQ3VW1CaCPH2SgQOLo2PZkgazG5TVos/Qym4z2kO/YDQbUANlcHL6IY2LRzDN QwOK9n4Yg25mHaetXKChEtplgUAspPksAKlUdSL05akFyhIfJqt0UFnR/lLCBuG4qkSM 5oKQ== MIME-Version: 1.0 X-Received: by 10.180.106.97 with SMTP id gt1mr73006wib.37.1434054126394; Thu, 11 Jun 2015 13:22:06 -0700 (PDT) Sender: are.you.winning@gmail.com Received: by 10.181.23.193 with HTTP; Thu, 11 Jun 2015 13:22:06 -0700 (PDT) In-Reply-To: <55794DE2.2080602@gmail.com> References: <5576051A.3040800@gmx.de> <55760771.6020802@gmail.com> <778F345F9918474AB8CAAB03082ECBF7@pc1> <5577DEE4.8030205@gmail.com> <55794DE2.2080602@gmail.com> Date: Thu, 11 Jun 2015 21:22:06 +0100 X-Google-Sender-Auth: pZkAuIozZnnOH2FHKp1SzxKktjo Message-ID: To: Rowan Collins Cc: PHP Internals List Content-Type: multipart/alternative; boundary=f46d04428066cae357051843be0f Subject: Re: [PHP-DEV] Array dereferencing of scalars From: cw@daverandom.com (Chris Wright) --f46d04428066cae357051843be0f Content-Type: text/plain; charset=UTF-8 On 11 June 2015 at 09:59, Rowan Collins wrote: > Yasuo Ohgaki wrote on 11/06/2015 00:50: > >> If PHP should return NULL always against NULL variables, we may be better >> to >> reconsider these behavior. >> >> [yohgaki@dev Download]$ php >> > $v = NULL; >> $$v; >> >> >> PHP Notice: Undefined variable: in - on line 3 >> > > This is not complaining that $v is NULL, it is warning you the same as if > you wrote $v = 'some_name_you_never_assigned_to'; $$v; > > Somewhat surprisingly, you can actually assign to the variable whose name > is NULL: http://3v4l.org/5pXJg This is actually just converting $v to a string and using this as the variable name to look up in the symbol table: http://3v4l.org/Z1fWs (obvious I suppose, just to clarify) > > > [yohgaki@dev Download]$ php >> > $v = NULL; >> $v(); >> >> PHP Fatal error: Uncaught EngineException: Function name must be a string >> in -:3 >> Stack trace: >> #0 {main} >> thrown in - on line 3 >> > > This one has given a different message because of it being a non-string > value, but would be equally fatal if you tried to call any undefined > function. Would coercing NULL to an imaginary function which returns NULL > actually be useful for anything? > > I don't care much whether these yield NULL always or raise >> error/exception, >> but there should be consistency. >> > > I see no reason why these cases need to be consistent, just because they > both involve NULLs. It's all about the action you invoke, not just the > value something's interpreted as. I think what Yasuo is saying is that the function symbol lookup has a type check and an early bail-out if the type doesn't make sense - even though in theory the same string cast behaviour could be applied to dynamic function calls. I'm inclined to agree that we should have consistency here, and that the current behaviour in a function context is the correct one. A couple of (IMO) good arguments for this: - The function behaviour gives a more explanatory and useful error message - This is definitely a programming error, there is no valid reason to use NULL as a variable name in this manner. It amounts to what many/most other languages would consider to be a "null pointer exception" or equivalent, and the more useful error message may help track down the error quicker (one might look for a case where the empty string was assigned, instead of looking for a case where it may be NULL). > > > -- > Rowan Collins > [IMSoP] > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d04428066cae357051843be0f--