Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101997 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30200 invoked from network); 22 Mar 2018 13:45:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Mar 2018 13:45:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=info@eordes.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=info@eordes.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain eordes.com from 209.85.128.180 cause and error) X-PHP-List-Original-Sender: info@eordes.com X-Host-Fingerprint: 209.85.128.180 mail-wr0-f180.google.com Received: from [209.85.128.180] ([209.85.128.180:38560] helo=mail-wr0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D4/13-03694-183B3BA5 for ; Thu, 22 Mar 2018 08:45:38 -0500 Received: by mail-wr0-f180.google.com with SMTP id l8so8760234wrg.5 for ; Thu, 22 Mar 2018 06:45:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eordes-com.20150623.gappssmtp.com; s=20150623; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=CrTebegG+BGnXV5/iWghXcelJL1lLF378mCGq30gJM4=; b=qNWo6RsWIR5ityejgse5IQYwITTf9tR0IzggH6RPzHcqZ4cE2+w2tzVtxhPnmAZi2t 9RMzE974DI1DU0Q0LmVeYfDeFu/opJavdjhm1T3njJ87yZdm1NiZJtWKhlousSkNzJed CYuSBl02VwUxQhTKtqw+cQDpd69mdQsWgimokd8Azzz1cuaa0tYHOs9kp097UHlkWPR8 kFAYMuO0FI4dPY+w2uOK3jmAth0+ej+wwxggFYK2dQCfeo29WHuEfCWYYCKWg+TGD5rX +k0BEUimNo5NkF3W79oDYCpWB6+mtdedpEUKq+wPASk4AHGji4RHF/mtp2v6KfqgzjhT VO3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=CrTebegG+BGnXV5/iWghXcelJL1lLF378mCGq30gJM4=; b=SeTrDyhNdZa7Zp0AWoXli1wB5K7H0BOvnkdNZImuod03pb5/c7Lzl9pRM6zjOh0Vue loAZQj4iejYJDKbViKsu9NdbF8JZWlFutF4mUIk2vzu8Qpb50sWwvYNxcwKF2kbq94DS BcQIWNEGeo+zoP00F+fzWYMFDmvdFrHO/cGcANfhvPJyT9R2LMKPP9oPbeOdSXmJrgqB cVyMpuq+abOdUdsLFZMUCP22GhpJF3HcqXtDzoNp49eNUC219YPniDCXwv9o7XxiTiyb MWGyTInuVVBs04+rXLv/Vk9qotyyLjxF297lyUU888Sz5Vgu1X3t11l+RQzlyztvfaX8 mwlw== X-Gm-Message-State: AElRT7GinAqwJeeXkIbwF/DK+TpAmyL5gqp/b2Bkwbdh2q6jc87cGcxg 7kTL5jRyGApOA1JN31SzspzuvFoN X-Google-Smtp-Source: AG47ELtJpSnAHBh7J6ARChxbSXa48VEsIQG3KuJ2Y0DdOU3JLk44Pw2rgUTLgqybDIHufPBOTlBbhg== X-Received: by 10.223.195.132 with SMTP id p4mr1904379wrf.279.1521726333631; Thu, 22 Mar 2018 06:45:33 -0700 (PDT) Received: from [192.168.0.20] (static-144-248-27-46.ipcom.comunitel.net. [46.27.248.144]) by smtp.gmail.com with ESMTPSA id j6sm8566096wmg.14.2018.03.22.06.45.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 06:45:31 -0700 (PDT) To: PHP Internals List References: <6fac0482-93fe-b15f-632c-1058232abcf0@eordes.com> <12ad9ff5-10bb-8a0d-5048-a5d30849a2ba@eordes.com> Message-ID: Date: Thu, 22 Mar 2018 14:45:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <12ad9ff5-10bb-8a0d-5048-a5d30849a2ba@eordes.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: es-CO Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Improve null-coalescing operator (??) adding empty check (??:) From: info@eordes.com (Lito) This is a RFC karma request for my wiki account. I want to create a RFC with my proposal: Improve null-coalescing operator (??) adding empty check (??:) First list message is: http://news.php.net/php.internals/101606 The main idea is simplify "empty" check on non existing keys or object attributes. Same as "?:" but also checking undefined. Current check: $value = empty($user->thisOptionalAttributeCanBeEmptyOrNotExists) ? 'without value' : $user->thisOptionalAttributeCanBeEmptyOrNotExists; New feature: $value = $user->thisOptionalAttributeCanBeEmptyOrNotExists ??: 'without value'; I think that could be very usefull on inline "exists" + "not empty" checks with a more clear code. It's possible? Thanks, Lito. On 17/01/18 19:47, Lito wrote: > On 17/01/18 19:43, Andrey Andreev wrote: >> Hi, >> >> >> On Wed, Jan 17, 2018 at 8: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... >>> >>> Anyway thanks for your feedback. >>> Lito. >>> >> There is a shorter version: >> >>      empty($foo) ? 'default' : $foo; >> >> And I think that's quite convenient for the few use cases it has >> (refer to Nikita's reply). >> >> Cheers, >> Andrey. >> > Yes, I think that: > > $foo = $foo ??: 'default'; > > Is more clear and with less code than: > > $foo = empty($foo) ? 'default' : $foo; > > As ?? does. > > Regards, > Lito. > >