Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62493 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80837 invoked from network); 25 Aug 2012 17:49:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Aug 2012 17:49:41 -0000 Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=krebs.seb@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-bk0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:41297] helo=mail-bk0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 61/BC-06857-43019305 for ; Sat, 25 Aug 2012 13:49:40 -0400 Received: by bkcjm19 with SMTP id jm19so886801bkc.29 for ; Sat, 25 Aug 2012 10:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=JhJKi5mvT3SAddRfdDKK26APs0/BCRNNkMfWQXDjjnE=; b=pjnw9AJbqfRMRiynW/rHcVLW475cbBzNinpzsKd3i0zqVUBlvd4BYWTv5SUS197nSH xkQKXj+D7Da1ssVFqWx6jC2reMRGbGGPX5ecUzHblGbsT3BkfBIEVWcDF9a1W+dLqRMt VnPvtV3uZZr/Vdpi9g4gNt35YeWxhyOIuc69+dHXmre2CD0pQYKWQloIlRDarDydLvgT Z8yOQMoVEpS0QC9San5vrhIf7zEgE70hvziyukZqw2bU7HCxKUUEogxOh9+shMha8iQa Zka/gNeF/f1hz9kfb+tkllwcAAYeB9n4zRybnJsAkuWCZ1CAs3Iu9aQCiahdqKGeIFDR OapA== Received: by 10.205.118.14 with SMTP id fo14mr2847678bkc.130.1345916977105; Sat, 25 Aug 2012 10:49:37 -0700 (PDT) Received: from [192.168.24.2] (91-66-42-108-dynip.superkabel.de. [91.66.42.108]) by mx.google.com with ESMTPS id c18sm7958870bkv.8.2012.08.25.10.49.36 (version=SSLv3 cipher=OTHER); Sat, 25 Aug 2012 10:49:36 -0700 (PDT) Message-ID: <5039102F.5010305@gmail.com> Date: Sat, 25 Aug 2012 19:49:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: PHP internals list References: <502EBAA4.9090007@gmail.com> <50381196.4090606@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Combined assignment operator for short ternary From: krebs.seb@gmail.com (Sebastian Krebs) Am 25.08.2012 18:38, schrieb Ferenc Kovacs: > > would this trigger a notice if $foo is not defined? > if yes, then it would be different from the current behavior of the > ternary operator. > > > Couldn't believe it, thus I tested it myself > > > snip > > Don't know, what you are talking about, but the notice _is_ the > current behaiour and therefore: No difference. > > > Sorry, I messed up that email. What I wanted to say: > If it accepts unset variable, then I could see usecases for it, but then > it would behave differently than the current ternary. > If it doesn't accept unset variable then it would in line with what we > have, but I don't see any usecase for it, because I would have to set it > before checking that it is falsely or not, in which case I would set it > to the default if not set already. > > > > if no, then I would never use this. > I mean if I have to set the variable before the check, then I > would put > the check into the assignment. > > > The main thought about it was > > function foo ($bar = null) { > $bar = $bar ?: 'default'; > } > > > If you wanted to enforce the 'default' value to be the default if no > argument passed, then you could use $bar = 'default' in the method > signature. > So I guess that you use that construct to handle when the argument is > passed, but it contains a falsely value ("0", array(), 0, etc.). > I agree that this can be useful in some cases. > > > I _always_ use 'null' as default > > > For me, it isn't always null, sometimes it is boolean true/false, or an > empty array. > > > - If you want to omit a parameter, but want to set one after that, > you don't need to look whats the default: It's 'null' > > > my IDE takes care of that problem for me. Only works on the green field ;) And/or if you are alone ... > > - Ive often enough seen something like > > function foo ($limit = 10) { /* code */ } > // Somewhere else > function bar ($limit = 50) { /* code */ $foo($limit); /* code */} > // Even somewhere else > bar(); > > > same here. Same here :p > > -- > Ferenc Kovács > @Tyr43l - http://tyrael.hu