Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99863 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88377 invoked from network); 12 Jul 2017 19:10:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jul 2017 19:10:51 -0000 Authentication-Results: pb1.pair.com header.from=mark@shust.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=mark@shust.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain shust.com from 209.85.218.46 cause and error) X-PHP-List-Original-Sender: mark@shust.com X-Host-Fingerprint: 209.85.218.46 mail-oi0-f46.google.com Received: from [209.85.218.46] ([209.85.218.46:33531] helo=mail-oi0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/A9-01782-A3476695 for ; Wed, 12 Jul 2017 15:10:51 -0400 Received: by mail-oi0-f46.google.com with SMTP id p188so27988621oia.0 for ; Wed, 12 Jul 2017 12:10:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shust-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=aYdi05VmMmzfpqAwY84tEJ1xsIiPzIweHDkivt/LxUg=; b=UiiU9NmaRrF6QAIQ05bNPDBbnjPhYLsgu7Ljehz+pH7+vb+j4t0qA/zIDFQMGqanAB +DG1SIAk0QyMB2nqURens5MpcOTXqXlvoSqyf2n2WpdF+/PbCMSnzjG0RcChVYX4tkWS l9Xp57YyuSNJ8mgu2NlhXNz0YUWEVo/A9DGvL2xS8d6S431nfW5XahyK4iQHPK1p4LBZ X7sF+u9l+NGXxWFs2Uyz5OXq+UCVs4TlY2SxXRy24a/6xT1WVluXUeHlfVhlbtHxrbvu ALTu+YkwQJ/8lX8cTaEcbUnqbPK7tcA+O5ZS84vuYHKfCjOkX2dK1OwcX0ieixVOxcjc 4BNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=aYdi05VmMmzfpqAwY84tEJ1xsIiPzIweHDkivt/LxUg=; b=iU3Gf2MWlcx/C1ucWoFir7Z/7QB8a7innmxl/CBvKC5DRuYqDQ9B6hlA8/x4wknzMB R8m94cjPW04aoq2C0g4T/rVuL7yEuPvmxKjspn1sx3xDuaIKekqQQHvi0gELUbgK/pzu oV+pRyJQ7iFHOG5euLIVSltxUDaaP4SSgIBQOmkIpAQJkGLqyWHbqd3ogiE9E3YJs7JZ vg8o1xkp6lvSYzI6YfwVWEnVDn/J0G9C5jMnw2vxgmuMVQ9X1dd25nY9lndHuildpaZK so6xTab1u1INSpoUC9U2Dxad7r4w3RD+3ow5MYT3BebqAhVFb8p/+icUwSNS0yzoxSZX lvKQ== X-Gm-Message-State: AIVw113ciDQpa04vclDQMED77A0KuyOzqIq7cP6daGY7QbqI4NhnwcKj BWzCFwgLHCxv+lgScgNo8FHMBpvpm41x X-Received: by 10.202.49.209 with SMTP id x200mr59820oix.107.1499886647940; Wed, 12 Jul 2017 12:10:47 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 12 Jul 2017 19:10:36 +0000 Message-ID: To: Stanislav Malyshev , internals@lists.php.net Content-Type: multipart/alternative; boundary="001a113cd50edaaf9f05542392dd" Subject: Re: [PHP-DEV] array coalesce operator concept From: mark@shust.com (Mark Shust) --001a113cd50edaaf9f05542392dd Content-Type: text/plain; charset="UTF-8" Stas, Wow, for some reason it didn't occur to me to try that. Confirming the following works: foreach ($foo ?? [] as $bar) { echo $bar; } I think the biggest need for this is if the value is null. Guess it's case-closed :) Might be a good idea to add this to the docs, pretty neat. Mark On Wed, Jul 12, 2017 at 2:00 PM Stanislav Malyshev wrote: > Hi! > > > Code will error if a non-array value is passed through a looping feature. > > For example, this code: > > > > > > > $foo = "abc"; > > > > foreach ($foo as $bar) { > > Looks like $foo??[] would work here. If $foo is something like false or > null, that is. If it's not, this is probably a serious bug (why would > you iterate on something that is a number or a non-iterable object) and > should be either fixed or resolved explicitly, not hidden. > > -- > Stas Malyshev > smalyshev@gmail.com > --001a113cd50edaaf9f05542392dd--