Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62488 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71826 invoked from network); 25 Aug 2012 16:38:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Aug 2012 16:38:25 -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:64996] helo=mail-pb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5A/FA-06857-E7FF8305 for ; Sat, 25 Aug 2012 12:38:22 -0400 Received: by pbbrp8 with SMTP id rp8so5155916pbb.29 for ; Sat, 25 Aug 2012 09:38:19 -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=Xb5PjiVmcH0RoGvi4k2eMZcPgRGOmX9ZqrQYCP+Dhv0=; b=URysIG8bv03gnBfGyZyYWMoJOHt8AzuuCUAqOzBoozj4AGndatvEGVNCewGYR1AOD6 N2fkwhrz+GHdjMfZgPjGn9q4hDvj2WA7Pm45gLCiqBxQnFPUCjag+NTlgzZcWIctmmLd vQ2Vn6npEea0kU26AGA7De3+CtpmDDBljPNEveRSpz3t+Dif2U3bSGkJbwsWaHSTkQuS tVgaCWHadYAJmk8tiRhhJeijs9ztm1bNjZk2DhVzLX6eI/WbRlnb5u0FrzdEHRjkNTxM BjCt5kHUfIwxEPIwbUv8c92tcAJyNI51KcYajLf+tJnJ1dk3oZqyC793R7sTswgrqIjl gaEQ== MIME-Version: 1.0 Received: by 10.68.222.40 with SMTP id qj8mr21406505pbc.139.1345912699439; Sat, 25 Aug 2012 09:38:19 -0700 (PDT) Received: by 10.68.211.37 with HTTP; Sat, 25 Aug 2012 09:38:19 -0700 (PDT) In-Reply-To: <50381196.4090606@gmail.com> References: <502EBAA4.9090007@gmail.com> <50381196.4090606@gmail.com> Date: Sat, 25 Aug 2012 18:38:19 +0200 Message-ID: To: Sebastian Krebs Cc: PHP internals list Content-Type: multipart/alternative; boundary=047d7b2ee2e959492b04c819b874 Subject: Re: [PHP-DEV] Combined assignment operator for short ternary From: tyra3l@gmail.com (Ferenc Kovacs) --047d7b2ee2e959492b04c819b874 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable > > >> 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. > - 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. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --047d7b2ee2e959492b04c819b874--