Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99835 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81895 invoked from network); 11 Jul 2017 15:25:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2017 15:25:00 -0000 Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.173 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.192.173 mail-pf0-f173.google.com Received: from [209.85.192.173] ([209.85.192.173:36462] helo=mail-pf0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/E7-47109-9CDE4695 for ; Tue, 11 Jul 2017 11:24:59 -0400 Received: by mail-pf0-f173.google.com with SMTP id q86so1336380pfl.3 for ; Tue, 11 Jul 2017 08:24:57 -0700 (PDT) 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=XnzkabuMb606x1V3CUtbpeSlF6be3AIeofc+PFEUtik=; b=hQWVL2vfMn6M5SxciLZf4ykFqf6Aj745AFuhw0Jm5IsEu1KcqP5od0fDSg6srgo8uP Bgmy1yEV5ImtxceuovgQwuv/z/lmAPTYEOEffi580S4TjVe8CIwChutsmhsU+XUNyY4D NYzX8iGpsdpTm0inD5YTng1Pjy1GHa7CQiuItMTyx1tDCKBLi71T3IexprgqyVMoudEs 8LhDXY+mzhYFlf7hn9PeOsJQ8KyPVjFcLlOqqS4b1n6ESiPD7xM+u/c39BPxtoMMnvWI e+IRbO6l7WQHlsN0Fcdfuve7yU8AN7Oejwt7OTId/xkZ8j+fnziRDCOMyloGMdxYHZ9z jahw== 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=XnzkabuMb606x1V3CUtbpeSlF6be3AIeofc+PFEUtik=; b=PLHwTABlqzIZQoYFAacl2vgwgaEInBqUTqSQ1+d9NCgXqNsV7LpMCPppjzfNRrWd5k /Wg4l9pG35YEmogwa6qtVreABIX8J3FqFdrR9EUi/Usn7ky4LJ14lAnwj0Q0pihYtqji Oyj9+fETB/ljJic6eAbA8OaDBZFdg6grJA6k6FjO90jMDYWSGJnhrSMp4tdNr6+59MIy gGuAMZ7+FRJxTOEHuOvFlU3hdbM37JqjIyrBJlieTlzPqYbyP33TAUkitq6JSNenFhQn blqT0r0uliPbWUlxDBEhv7XE0kahbgFOD60o2bmmPlrFN2ef136v8N9O26JZS7BnPLXx Bu4Q== X-Gm-Message-State: AIVw112epJjmsFajcDAUK//S5r2dFXRiqUnzGqgu9yhkdPlf0XqjF5qI 1UE1rX5mB8dznmaWTA4Bu4cEK2GObw== X-Received: by 10.98.149.12 with SMTP id p12mr51595013pfd.174.1499786695276; Tue, 11 Jul 2017 08:24:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.181.138 with HTTP; Tue, 11 Jul 2017 08:24:54 -0700 (PDT) Received: by 10.100.181.138 with HTTP; Tue, 11 Jul 2017 08:24:54 -0700 (PDT) In-Reply-To: References: Date: Tue, 11 Jul 2017 12:24:54 -0300 Message-ID: To: Mark Shust Cc: PHP Internals Content-Type: multipart/alternative; boundary="94eb2c115c1835fe9205540c4d46" Subject: Re: [PHP-DEV] array coalesce operator concept From: david.proweb@gmail.com (David Rodrigues) --94eb2c115c1835fe9205540c4d46 Content-Type: text/plain; charset="UTF-8" The idea is good, but I don't know if it is more clear than an 'if()' Em 11 de jul de 2017 12:15 PM, "Mark Shust" escreveu: > Hello, > > I wanted to garnish feedback on a RFC proposal. This is just a concept at > this point, and is inspired by the null coalesce operator. > > Code will error if a non-array value is passed through a looping feature. > For example, this code: > > > $foo = "abc"; > > foreach ($foo as $bar) { > > echo $bar; > > } > > > will result in the error: > > PHP Warning: Invalid argument supplied for foreach() in test.php on line 3 > > > To prevent this, the logical solution is to wrap this in an is_array check: > > > $foo = "abc"; > > if (is_array($foo)) { > > foreach ($foo as $bar) { > > echo $bar; > > } > > } > > > This code runs successfully and does not error out. For a syntactic > sugar/improvement, this can be shorthand for executing the loop instead of > wrapping the block within an is_array check: > > > > $foo = "abc"; > > foreach (??$foo as $bar) { > > echo $bar; > > } > > > Let me know your thoughts. > > > Cheers, > Mark > --94eb2c115c1835fe9205540c4d46--