Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62465 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71426 invoked from network); 24 Aug 2012 23:43:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Aug 2012 23:43:23 -0000 Authentication-Results: pb1.pair.com header.from=krebs.seb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.42 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wg0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:57196] helo=mail-wg0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/A8-24287-A9118305 for ; Fri, 24 Aug 2012 19:43:22 -0400 Received: by wgbfm10 with SMTP id fm10so1179753wgb.5 for ; Fri, 24 Aug 2012 16:43:19 -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=KSKwYOlWHp8Zrw7z+XOdh+QM8vw/5RapA0ue8rG+7xQ=; b=pqAbZhSLYT5+4Cgdg+txJ2IO7iT6JCuNECSB44amAhr6VfAxhq1IjJIYDVpOl7dNzC 7qVTyyjio2N/xyFYC1ozmlQH2SYF+89tKcaczG+cWJEfFsjDl185HOGDkmIF7mNY3mkg oCV/wmEsUReW0BpZxZzS2JfulKYMXq3BcuUGeLCkLGAASGveW48GfPKcfB6IGTfn+YT+ 8WKoJV2mLpAIquj6mQ+gIR1bro8SxbTuBFJnyoGZTa5WHvWWQMjK9fkMhsKw9YiE5rTx O/yYFM72FeFVMvy6Cj8v3MRjg9w/bd63uBNpOf5jCqYazuJhhgFDPLkqok3KyOhLc9Io O/zg== Received: by 10.180.96.3 with SMTP id do3mr8975244wib.5.1345851799667; Fri, 24 Aug 2012 16:43:19 -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 cu1sm1121165wib.6.2012.08.24.16.43.18 (version=SSLv3 cipher=OTHER); Fri, 24 Aug 2012 16:43:19 -0700 (PDT) Message-ID: <50381196.4090606@gmail.com> Date: Sat, 25 Aug 2012 01:43:18 +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> 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 24.08.2012 23:11, schrieb Ferenc Kovacs: > > > On Fri, Aug 17, 2012 at 11:41 PM, Sebastian Krebs > wrote: > > Hi, > > Don't know, how complicated this is (and also someone (not me) must > implement it, because I can't :X), but to be in sync with the > operators the short ternary operator should be usable in conjunction > with the assignment like the other binary operators. Don't know, if > anybody understands me :D So here is an example > > // instead of > $foo = $foo ?: 'default'; > // Just > $foo ?:= 'default'; > > > 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 $ php -a Interactive mode enabled 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'; } I _always_ use 'null' as default - 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' - 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(); Imagine there are some other methods and functions in between it's quite annoying. > > -- > Ferenc Kovács > @Tyr43l - http://tyrael.hu