Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62495 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84181 invoked from network); 25 Aug 2012 18:09:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Aug 2012 18:09:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; 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: tyra3l@gmail.com X-Host-Fingerprint: 209.85.160.42 mail-pb0-f42.google.com Received: from [209.85.160.42] ([209.85.160.42:44011] helo=mail-pb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7B/5D-06857-AE419305 for ; Sat, 25 Aug 2012 14:09:46 -0400 Received: by pbbrp8 with SMTP id rp8so5225899pbb.29 for ; Sat, 25 Aug 2012 11:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Hkc84SI3iYVxBZhuqhYhMpoX3UbQSRkZu/cJJ3Py/8s=; b=WXeqkImHE7q21x9I2HpaJuy4VkzVCP5bqjR+PPWMqN9XaDoP2u5JMBXDy0kmvNxkgX Tsn1M1jjCgRayKd1zVquj3R71kRlvklbphVCAY97UjElqtFS/g3jdSDpOk6PuP0CAEtJ KW01KCYW+4jkNPpiJkGTdlgOqurGrvxpABJ3Tif0jWpTEQybD0hEsdrNSCY1PfuxxQIo cdP0DSfcGwEtyfWSG1RBGbqt+tVbCwk/Fcb3pS2lkv/brEGpc4JaJPDqw7QK1WVa0DaI F7cfgvAQcKa9ayJdcd1yUckhW8NIGG+kLztd+8HRixA49FlL7EUwPu/cRM4qvTAj1EYG 1Dsg== MIME-Version: 1.0 Received: by 10.68.221.225 with SMTP id qh1mr22382332pbc.50.1345918183625; Sat, 25 Aug 2012 11:09:43 -0700 (PDT) Received: by 10.68.211.37 with HTTP; Sat, 25 Aug 2012 11:09:43 -0700 (PDT) Received: by 10.68.211.37 with HTTP; Sat, 25 Aug 2012 11:09:43 -0700 (PDT) In-Reply-To: <5039102F.5010305@gmail.com> References: <502EBAA4.9090007@gmail.com> <50381196.4090606@gmail.com> <5039102F.5010305@gmail.com> Date: Sat, 25 Aug 2012 20:09:43 +0200 Message-ID: To: Sebastian Krebs Cc: PHP internals list Content-Type: multipart/alternative; boundary=e89a8ff255c03b551104c81aff0a Subject: Re: [PHP-DEV] Combined assignment operator for short ternary From: tyra3l@gmail.com (Ferenc Kovacs) --e89a8ff255c03b551104c81aff0a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2012.08.25. 19:50, "Sebastian Krebs" ezt =C3=ADrta: > > 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 =3D null) { >> $bar =3D $bar ?: 'default'; >> } >> >> >> 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. >> >> >> 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 =3D 10) { /* code */ } >> // Somewhere else >> function bar ($limit =3D 50) { /* code */ $foo($limit); /* code */} >> // Even somewhere else >> bar(); >> >> >> same here. > > > Same here :p > > >> >> -- >> Ferenc Kov=C3=A1cs >> @Tyr43l - http://tyrael.hu > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > 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. --e89a8ff255c03b551104c81aff0a--