Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99871 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49475 invoked from network); 13 Jul 2017 18:14:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jul 2017 18:14:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=walterp@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=walterp@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.178 as permitted sender) X-PHP-List-Original-Sender: walterp@gmail.com X-Host-Fingerprint: 209.85.216.178 mail-qt0-f178.google.com Received: from [209.85.216.178] ([209.85.216.178:34196] helo=mail-qt0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2F/BE-01782-968B7695 for ; Thu, 13 Jul 2017 14:14:02 -0400 Received: by mail-qt0-f178.google.com with SMTP id 32so44709247qtv.1 for ; Thu, 13 Jul 2017 11:14:01 -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; bh=Oc6Py50TKIH48N84aKLfsrXmrps6WSu3pK0IFEMEGqE=; b=KfEqQ1z1WdaDzzJyz5PHN+8NoHBAYUpzEBE7CVmuq15wKEaxNk+l1SYaOWRAzrL82C AmadRx6Qsoeo/ZWZBIXEMacFjsSSLZHJpLylfUIxRszGYjVtxGfuC5+opBW4jPeS2NnO sYr8DrFLWqjT00ztzvFRB/m4KDk3n/12fkXBum7TXUIg+HUumdg6rSBn/SNtEWax3vtm 4pHdGtuU25NpfhI56GRSY/h/9VT+8mS/vBbs0aZ+8AKLMlpeB2kd9q4nTfzi8t83vC2R EthTzTwj/KTt3AG8bPExolxVfOcmdF8bx12yM97491H7GKJV3/WlUf0zAHaovt4ztOTS rF1g== 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; bh=Oc6Py50TKIH48N84aKLfsrXmrps6WSu3pK0IFEMEGqE=; b=eXkd5M1HqH/ikGfUpltb1Ma0FM+yCeEnafFsRFnR/4CtBo0TS8uXwkAgo5afYvC/n+ TJE1OJb7s188UOYZK0l7Ele+opKrC5w0gS+8mSg60if+yC5jK5IuKJzKZ/sPiAMXQ5Sw bMzsUWLsHacnJDT0JWpbVLXMTJyLzgwxFXCpvLR6SUAijqb+1QVwRYJuJLF+vFQun/aN PjXb0dENwih4IEnOEN2zVGEdKJtbow/UDxq//wvohBtX3FUpIYrH7+9j0u1ivGwADgdG csOE8F8vRHWqiZk4UDXagpfVs9QdOODOF4XZElKpSaOfOxDBqu1VVeSLHfc7TT/8eRvi e7Cw== X-Gm-Message-State: AIVw11086LRVSbnF35bkZAdems8y/nCv0wfGQgx6rgScrRbjtZ7Q/v7B eGnrJnsiD/l03/K9BwsAfIyIznx8JA== X-Received: by 10.200.42.27 with SMTP id k27mr6520663qtk.40.1499969638061; Thu, 13 Jul 2017 11:13:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.145.220 with HTTP; Thu, 13 Jul 2017 11:13:57 -0700 (PDT) In-Reply-To: References: Date: Thu, 13 Jul 2017 11:13:57 -0700 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="001a11407f86735bcc055436e5da" Subject: Re: [PHP-DEV] array coalesce operator concept From: walterp@gmail.com (Walter Parker) --001a11407f86735bcc055436e5da Content-Type: text/plain; charset="UTF-8" On Thu, Jul 13, 2017 at 2:55 AM, Tony Marston wrote: > "David Rodrigues" wrote in message news:CAEsg9X2ECG62i7Z_Nu11kqr7 > yVBkmUcd3MxGt78ULAmpFx--_w@mail.gmail.com... > >> >> The idea is good, but I don't know if it is more clear than an 'if()' >> > > I think that this proposal is totally ridiculous and should be shot down > in flames. My reasoning is as follows: > > 1) There should be a rule that anything which can be achieved with 5 lines > or less in userland code should be automatically excluded from becoming a > change to the language. The cost of changing the language in order to get > around the laziness of a small number of users versus the "benefit" of > making the language more complicated for the rest of us, as well as adding > to the maintenance burden is simply not worth it. > > 2) Proposals such as this violate the first rule of good programming which > is to provide code which is readable and therefore understandable by > others, and therefore maintainable. I don't know about you, but I find it > much easier to read words than symbols. The idea that the code "if > (is_array($foo))" is too verbose and should be replaced with a shorthand > symbol is just too ridiculous for word. If any more of these shortcuts is > implemented then I'm afraid that code will look too much like a bunch of > hieroglyphics and become far less readable. > > Just my 2 cents worth. > > -- > Tony Marston > > > 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 >>> >>> > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > The more I think about this, the more I think that the throwing a warning when the variable is not an array is the proper thing to do. The cost in missed mistakes is much larger than the tiny savings in code that some people would get. Walter -- The greatest dangers to liberty lurk in insidious encroachment by men of zeal, well-meaning but without understanding. -- Justice Louis D. Brandeis --001a11407f86735bcc055436e5da--