Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51892 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27632 invoked from network); 14 Apr 2011 11:58:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Apr 2011 11:58:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=mail_ben_schmidt@yahoo.com.au; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=mail_ben_schmidt@yahoo.com.au; sender-id=unknown; domainkeys=good Received-SPF: error (pb1.pair.com: domain yahoo.com.au from 98.139.52.211 cause and error) DomainKey-Status: good X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: mail_ben_schmidt@yahoo.com.au X-Host-Fingerprint: 98.139.52.211 nm14.bullet.mail.ac4.yahoo.com Received: from [98.139.52.211] ([98.139.52.211:29638] helo=nm14.bullet.mail.ac4.yahoo.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 71/20-25347-F41E6AD4 for ; Thu, 14 Apr 2011 07:58:07 -0400 Received: from [98.139.52.195] by nm14.bullet.mail.ac4.yahoo.com with NNFMP; 14 Apr 2011 11:58:05 -0000 Received: from [98.138.90.55] by tm8.bullet.mail.ac4.yahoo.com with NNFMP; 14 Apr 2011 11:58:05 -0000 Received: from [98.138.89.172] by tm8.bullet.mail.ne1.yahoo.com with NNFMP; 14 Apr 2011 11:58:04 -0000 Received: from [127.0.0.1] by omp1028.mail.ne1.yahoo.com with NNFMP; 14 Apr 2011 11:58:04 -0000 X-Yahoo-Newman-Id: 953920.81986.bm@omp1028.mail.ne1.yahoo.com Received: (qmail 75838 invoked from network); 14 Apr 2011 11:58:04 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com.au; h=DKIM-Signature:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=VYCzxNtgtRp0nMWS80PdplLdZHk/v1XQ5p8zm9PasvL1ifXrhMHlA42OGxTPf6pP2LPabJzYSLxhDbjoGOn5dLIPEpGzpZd6wvASgY5J4OdKf2WQYa7nWesjHb+0/N7QFfJ2diCnhkBXyNLid4od8Qr7khWySGTO3j7LjlYdnws= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com.au; s=s1024; t=1302782284; bh=ek1JvA42DeGzng4/k6xucrGr7xqbCNtNPwWwWPOOG2I=; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=akPKNMEW5uGxA1ua5msWPpX4DnsxWZSk3hPaA2E5S7yISi2aUOjqIZ0BMfM+0R4AHloKQTLojTyEY7tNyeCE5O5pKssQCxSdCMWh33lCMvIW8Z4lL0TgCf7Xm6FEg8tXRwc68FO/xWRXrneUwU0S2XulQof2u5zFKdAPn0n+KlA= Received: from thought.local (mail_ben_schmidt@124.168.69.175 with plain) by smtp141.mail.mud.yahoo.com with SMTP; 14 Apr 2011 04:58:03 -0700 PDT X-Yahoo-SMTP: enFMnPSswBAexaHyzgobwuUTrYOhZdJ0KRA2SjA- X-YMail-OSG: B0lKdMgVM1m.DBSVK7KorgTCzZ.cNbzTMxxBSh6C5KAdzmZ JoMNSChli.nXvAqDNK52_Favc1bXR2cKZSloE_UBxVzU28PhF3gLtl2ITZVe N0Hn.qcuapWtXPcpWNXZSuRBwItN78B9djpo60adqwB0IvjoKv6cPGp6fl3Y VbiVWGEG467f2Acd8GrqqtsA8FXO4QnMgzaLncAJ5qpVS_HnEm4GEQKItZQi fSO6QlqwtrrCvu.fDu4NE.x2Uzahw4M3iBjzah6GyjTdm7_BoCwkr1CIAsDn QIHonL0g8hYDDg8bjTu48ii9.S_CzSOLp3mFdu1ctNEP4iRCo3NxyKgVC672 cv3VplJ_skgVZAYOZWJmwX.vlGg-- X-Yahoo-Newman-Property: ymail-3 Message-ID: <4DA6E151.4030707@yahoo.com.au> Date: Thu, 14 Apr 2011 21:58:09 +1000 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-GB; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 ThunderBrowse/3.3.5 MIME-Version: 1.0 To: Ole Markus With CC: "internals@lists.php.net" References: <4D950434.3060704@yahoo.com.au> <4D9E0543.1080600@lerdorf.com> <69.82.36433.EC33E9D4@pb1.pair.com> <4D9E34C4.5000406@lerdorf.com> <4D9E429B.20503@sugarcrm.com> <4D9E96B6.6060401@lerdorf.com> <718216446.20110408143441@cypressintegrated.com> <4DA0E71C.9030008@gmail.com> <4DA63ED8.4080402@yahoo.com.au> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: mail_ben_schmidt@yahoo.com.au (Ben Schmidt) >> 1. Suppression of notice. I agree, it is best done only for array >> keys. It's not hard to initialise a variable with $var=null at the >> beginning of a code block to avoid such a notice, and that is the >> appropriate way to do it for variables. >> >> 2. Offering a shortcut for the common idiom isset($x) ? $x : $y in >> line with the DRY design principle. A notice would never be emitted >> here in any case. The problem is that this idiom is still in wide use >> despite the shortcut ternary operator already provided, because an >> isset() check is different to a boolean cast. >> >> Some thoughts: >> >> - The actual intent of 2. is probably $x!==null ? $x : $y i.e. it's >> not about suppressing notices at all, but about offering a default >> value, and the idiom quite probably only uses isset() because it >> predated null in the language. >> > I have never felt the need for a shortcut in these cases. It would be > interesting to see some code where this would be practical. I have many, many uses for this. E.g. patterns like this: class Foo { private $defaultBar; public function foobar(Bar $bar=null) { $bar = isset($bar) ? $bar : $this->defaultBar; $bar->doSomething(); } } The default value of null indicates that the argument is able to be omitted, and the type hinting mechanism understands that. Yet it's awkward to actually test whether it's been omitted or not without writing the argument multiple times. It'd be great to be able to write the first line succinctly, e.g. $bar $:= $this->defaultBar; That's just one case. There are many more. As I said above, though, I probably should have written $bar!==null rather than isset($bar), because I actually would want the warning if $bar was not defined (i.e. I had mistyped it). >> - If we view 2. in this way, the two problems are independent, and it >> seems to me it would be best to solve them independently, rather >> than with a single operator. >> >> So, I suggest: >> >> 1. An array lookup mechanism that suppresses the notice for undefined >> keys. It would work the same as regular array index lookups except >> that the notice for undefined keys (and only for undefined keys) >> would not be generated (it would not just be hidden, but would never >> be even generated). > > This is what I feel PHP is missing. Particularly when it comes to > multi-dimensional arrays. Because this feature is missing I tend to do > something like > > function generateHash($x, $y, $z) > { > return "$x::$y::$z"; > } > > if (isset($a[generateHash($x, $y, $z)]) { > ... > } > > instead of > > if (isset($a[$x]) && isset($a[$x][$y]) && isset($a[$x][$y][$z])) { > ... > } I don't really understand your example, or how an error-suppressing array index lookup helps it, but I do think the feature is useful. I actually think there is enough support for both these things, and implementing them independently allows those who want to use one but not the other to do so. >> Arguing about syntax is then a second step. However, my views on this >> are: > > I think it best to avoid discussing the actual syntax before agreeing on what we > really need. I agree. In fact I sent the previous mail by mistake; I had intended to archive my thoughts on syntax and send the mail without them, but I bumped send. Ben.