Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101610 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73582 invoked from network); 17 Jan 2018 18:36:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jan 2018 18:36:05 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.47 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.47 mail-it0-f47.google.com Received: from [209.85.214.47] ([209.85.214.47:44175] helo=mail-it0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/00-12394-5979F5A5 for ; Wed, 17 Jan 2018 13:36:05 -0500 Received: by mail-it0-f47.google.com with SMTP id b5so10367675itc.3 for ; Wed, 17 Jan 2018 10:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=bi34IWeYOp41tG4LPnuP7XlmBPVI4i97mMizzmOM7kU=; b=c9BwN4rqRvPv3VEsvVAV/gl7treANWvP/7PFgTCH9hzZV6pwRMPDoOaJvTaHSN4xWf WwE1qiH3YHKlFv+IdpCIl+O3o0CVPaIs/IrKLuKc2sAmqTKjYFCCOZzPsV0dKrB5h9qh ljXhEs8TEfxrWkVuTvHQnGLyopwT5UARANA/fd1WzBOPCp9jrywGUJFCSly5gGFPa0QP zK6ghJ7QeLhmrw+rx2g/rfcvdSCSsjh97Am5tEb25AfePW/D4p/nt1jthnVIxsh2LW8w n/11cpmIZaRKRCVg9EYlLfdjIcham4DTI2gFy1nNCPJLynFC1DyeYLOcgSMESE0VQp/s I/8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=bi34IWeYOp41tG4LPnuP7XlmBPVI4i97mMizzmOM7kU=; b=rOecxBuJ2NBKqerWRVbUHNqysh1VqHQK1YVi0JXvXaMHlJcSD2/DZ5Ug2m8+Y2n2KF 89TZ3UqHJiwjLyuUUy2jmEpe+0mDLzeBrPjNRDVl8AhymAGJ+7vjv3jEtIHKAhBPPdFx TXoIuDiS/qaXHpWLCLj4moPIHFEMeO2tjbN/e7Rs/El985kqKrY4DdQBMhZLu1o8njQd 14B5xSNGRAL8e+lqIhWDTU3YGUgYCVz8hTzfOntFJfD+iRS3i8THiZNUw6TB1kMlAska cN4RpxxctgviIIkqM/+rqdKGL9AbJ5/s2w3IGlwvPrc97Mcnzw8IVHYtuMA1v/NxXiCt ASzQ== X-Gm-Message-State: AKwxytdOKLFLN+BRyZiLqswZhV9fzBAqh5BttA9qZFZrBtQD52FENeKr pTBoagEjexHi2GwgenIpuNb3LB5anNQgUxz3yt8= X-Google-Smtp-Source: ACJfBoukj6Ug+oa/Exc89SKxWcJL608H9HSVWQJfOWWlvpoG4qrh30TWs8shO2K7Hm3pyZNbXvYnCk6b9bz/iquYEKc= X-Received: by 10.36.209.5 with SMTP id w5mr25710436itg.63.1516214162590; Wed, 17 Jan 2018 10:36:02 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.135.159 with HTTP; Wed, 17 Jan 2018 10:36:01 -0800 (PST) In-Reply-To: References: <6fac0482-93fe-b15f-632c-1058232abcf0@eordes.com> Date: Wed, 17 Jan 2018 19:36:01 +0100 Message-ID: To: Lito Cc: Marco Pivetta , PHP Internals List Content-Type: multipart/alternative; boundary="94eb2c0b09b69091ae0562fd1ea1" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Improve null-coalescing operator (??) adding empty check (??:) From: nikita.ppv@gmail.com (Nikita Popov) --94eb2c0b09b69091ae0562fd1ea1 Content-Type: text/plain; charset="UTF-8" On Wed, Jan 17, 2018 at 7:28 PM, Lito wrote: > No $foo ?: 'default' , it's only equivalent to (isset($foo) && $foo) ? > $foo : 'default' if $foo exists. > > Also PHP has added ?? as null-coalescing operator that works with > undefined variables/attributes/keys, my proposal is an improvement over > this one. > > I don't want to endorse usage of undefined variables, can be used in a > large set of situations, like object attributes, array keys, etc... > What is the use case for the ??: operator? Null-coalesce is very common, because undefined/null are typically used to signal default values. Using *any* falsy value to indicate a default value seems a lot more unusual and precarious to me, especially if you consider PHP's specific semantics around falsiness (with the string "0" being falsy). Nikita > On 17/01/18 19:17, Marco Pivetta wrote: > >> This: >> >> echo (isset($foo) && $foo) ? $foo : 'default'; >> >> Is equivalent to: >> >> echo $foo ?: 'default'; >> >> Please don't endorse usage of undefined variables. >> > --94eb2c0b09b69091ae0562fd1ea1--