Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46147 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24014 invoked from network); 21 Nov 2009 18:21:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Nov 2009 18:21:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.210.192 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.210.192 mail-yx0-f192.google.com Received: from [209.85.210.192] ([209.85.210.192:44615] helo=mail-yx0-f192.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 67/38-13841-5AF280B4 for ; Sat, 21 Nov 2009 13:21:26 -0500 Received: by yxe30 with SMTP id 30so4640703yxe.29 for ; Sat, 21 Nov 2009 10:21:23 -0800 (PST) Received: by 10.150.14.3 with SMTP id 3mr5100726ybn.288.1258827682651; Sat, 21 Nov 2009 10:21:22 -0800 (PST) Received: from ?192.168.200.22? (c-98-234-184-167.hsd1.ca.comcast.net [98.234.184.167]) by mx.google.com with ESMTPS id 20sm937324ywh.47.2009.11.21.10.21.20 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 21 Nov 2009 10:21:21 -0800 (PST) Message-ID: <4B082F9E.6080703@lerdorf.com> Date: Sat, 21 Nov 2009 10:21:18 -0800 User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Alban CC: internals@lists.php.net References: <17.CC.25743.CB6770B4@pb1.pair.com> <84B23126-8011-48DA-B65A-750AA9C5B57E@pooteeweet.org> In-Reply-To: X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] suggestion about ternary operator From: rasmus@lerdorf.com (Rasmus Lerdorf) Alban wrote: > Le Sat, 21 Nov 2009 09:48:10 +0100, Lukas Kahwe Smith a écrit : > >> On 21.11.2009, at 06:12, Alban wrote: >> >>> This is not a big problem but if a solution exists, this would be so >>> cool ! Especialy when we have to check existance of twenty or more key >>> in array. Code would be be lighter and clear. Since i use PHP, I always >>> have in my 'common function file' a function like that : >>> >>> function getIssetVar($var, $default) { return ((isset($var)) ? $var : >>> $default); } >>> >>> So is it possible to make a little improvement on this operator or >>> introduce a new operator or a core function which do that ? What's your >>> feeling about it ? >> >> this feature request has already been discussed and declined: >> http://wiki.php.net/rfc/ifsetor >> >> please review this rfc before continuing this thread. >> >> regards, >> Lukas Kahwe Smith >> mls@pooteeweet.org > > Thanks for the link to the RFC :) > > Excuse me, but I'll be little hard in this post. This for insult the > community but I want the community really think about the decision it > made and the reason why. > > I also read why it have been refused here : > http://www.php.net/~derick/meeting-notes.html#ifsetor-as-replacement-for- > foo-isset-foo-foo-something-else > > Is it serious ? > > « > The name for this new operator is heavily disputed and we could not agree > on a decent name for it. > » > > Tomorrow I will not send food to the association for children who are > hungry because I can not choose between offering Thai or basmati rice. > > Stop sarcasm, seriously, this is not an honorable response from people > making decisions. Take your responsibility and make a vote or impose a > name, just do it. > > « > Instead of implementing ifsetor() we remove the > requirement for the "middle" parameter to the ?: operator. > » > > That's not people wants and that's not do their need. > So that not a correct answer of the php developper demand. > > « > In combination with the new input_filter extension > you then reach the original goal of setting a default > value to a non-set input variable with: > > $blahblah = input_filter_get(GET, 'foo', FL_INT) ?: 42; > » > > I don't see how do that with the actual filter extension. Even if it is > possible, this is not a pretty short and easier solution than : > > $var = (isset($var)) ? $var : 'default'; The ternary isn't meant to solve the isset thing you are talking about. It is simply a shortcut to normal ternary operations. The most common case where you don't know if a variable is set is on the initial input via $_GET or $_POST and we definitely don't want people doing: $var = $_GET['foo'] ?: 42; It would be an XSS disaster. Hence the suggestion to use input_filter there, or a similar user-supplied filtering function in which case the ternary, as it is currently implemented, is perfectly suitable. -Rasmus