Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62502 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35715 invoked from network); 25 Aug 2012 23:31:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Aug 2012 23:31:01 -0000 Authentication-Results: pb1.pair.com header.from=davidkmuir@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=davidkmuir@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.42 as permitted sender) X-PHP-List-Original-Sender: davidkmuir@gmail.com X-Host-Fingerprint: 209.85.160.42 mail-pb0-f42.google.com Received: from [209.85.160.42] ([209.85.160.42:54186] helo=mail-pb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F8/97-06857-13069305 for ; Sat, 25 Aug 2012 19:30:58 -0400 Received: by pbbrp8 with SMTP id rp8so5422923pbb.29 for ; Sat, 25 Aug 2012 16:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:in-reply-to:mime-version:content-transfer-encoding :content-type:message-id:cc:x-mailer:from:subject:date:to; bh=pImkgyHMv+73rG8LysUXP0SXVlormGEFxBHQ7uw6oBU=; b=k8ELyo0ylQ2YHVADikzdiiR3O/AEm+xTn8Eb2FS3Rs8USJDTEfS5sXne6WRC9Zf5iL eIK38NOX+BNnDFEAqwIUeb680bKHuxkGkhyq/srFelZBNUyrg8Ti/N4MFgSwMHJoM9yz iKGlDT//AfWZdr2kv1xOEGFqE3D3FAAS0tRxs4nvmj42/Z7P63A6a8PghF2aqrzuR3xM h53+VmqiaHMNuI5jMISigelNYy+/YLct1zbkw5k/HASFQCS3wYan4kGPpFXxEpqGR9AM 7Bkg4FWOIW1hS4ruAaDJoWZJlPDRFnO0q7enW0zGWmVwkKh2KahpnP1C2cUJKzvaz2dF xSzQ== Received: by 10.68.189.99 with SMTP id gh3mr23265467pbc.31.1345937454500; Sat, 25 Aug 2012 16:30:54 -0700 (PDT) Received: from [192.168.0.8] (dsl-202-173-152-56.vic.westnet.com.au. [202.173.152.56]) by mx.google.com with ESMTPS id rn4sm11336604pbb.51.2012.08.25.16.30.52 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 25 Aug 2012 16:30:53 -0700 (PDT) References: <502EBAA4.9090007@gmail.com> <50381196.4090606@gmail.com> <5039102F.5010305@gmail.com> In-Reply-To: Mime-Version: 1.0 (1.0) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Message-ID: Cc: Sebastian Krebs , PHP internals list X-Mailer: iPhone Mail (9B206) Date: Sun, 26 Aug 2012 09:30:48 +1000 To: Ferenc Kovacs Subject: Re: [PHP-DEV] Combined assignment operator for short ternary From: davidkmuir@gmail.com (David Muir) On 26/08/2012, at 4:09 AM, Ferenc Kovacs wrote: > 2012.08.25. 19:50, "Sebastian Krebs" ezt =C3=ADrta: >>=20 >> Am 25.08.2012 18:38, schrieb Ferenc Kovacs: >>=20 >>>=20 >>> 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. >>>=20 >>>=20 >>> Couldn't believe it, thus I tested it myself >>>=20 >>>=20 >>> snip >>>=20 >>> Don't know, what you are talking about, but the notice _is_ the >>> current behaiour and therefore: No difference. >>>=20 >>>=20 >>> 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. >>>=20 >>>=20 >>>=20 >>> 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. >>>=20 >>>=20 >>> The main thought about it was >>>=20 >>> function foo ($bar =3D null) { >>> $bar =3D $bar ?: 'default'; >>> } >>>=20 >>>=20 >>> If you wanted to enforce the 'default' value to be the default if no >>> argument passed, then you could use $bar =3D '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. >>>=20 >>>=20 >>> I _always_ use 'null' as default >>>=20 >>>=20 >>> For me, it isn't always null, sometimes it is boolean true/false, or an >>> empty array. >>>=20 >>>=20 >>> - 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' >>>=20 >>>=20 >>> my IDE takes care of that problem for me. >>=20 >>=20 >> Only works on the green field ;) And/or if you are alone ... >>=20 >>=20 >>>=20 >>> - Ive often enough seen something like >>>=20 >>> function foo ($limit =3D 10) { /* code */ } >>> // Somewhere else >>> function bar ($limit =3D 50) { /* code */ $foo($limit); /* code */} >>> // Even somewhere else >>> bar(); >>>=20 >>>=20 >>> same here. >>=20 >>=20 >> Same here :p >>=20 >>=20 >>>=20 >>> -- >>> Ferenc Kov=C3=A1cs >>> @Tyr43l - http://tyrael.hu >>=20 >>=20 >>=20 >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >>=20 >=20 > So you are saying that your (teams) IDE doesn't tell you the method > signature which contains also the default values? > I guess that the fact that many of the php core functions have optional > arguments and non null defaults must be really a PITA for you. I think what he was alluding to is the problem where one changes the default= . All usages of the method/function then need to be updated. Using null toda= y is very much like using the proposed 'default' parameter skipping RFC. Cheers, David=