Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100725 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69224 invoked from network); 20 Sep 2017 17:30:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Sep 2017 17:30:51 -0000 Authentication-Results: pb1.pair.com header.from=lists@rhsoft.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=lists@rhsoft.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain rhsoft.net designates 91.118.73.15 as permitted sender) X-PHP-List-Original-Sender: lists@rhsoft.net X-Host-Fingerprint: 91.118.73.15 mail.thelounge.net Received: from [91.118.73.15] ([91.118.73.15:34307] helo=mail.thelounge.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/8A-62331-9C5A2C95 for ; Wed, 20 Sep 2017 13:30:50 -0400 Received: from srv-rhsoft.rhsoft.net (Authenticated sender: h.reindl@thelounge.net) by mail.thelounge.net (THELOUNGE MTA) with ESMTPSA id 3xy6GD3kXGzXMf for ; Wed, 20 Sep 2017 19:30:44 +0200 (CEST) To: internals@lists.php.net References: <0040eda1-f2d4-408e-a3e1-fe3daf756dfd@Spark> <75c3c518-56db-4887-99c7-32685e6e5f76@Spark> Message-ID: <424aa524-a541-7f0f-868f-b4b60ed0a39f@rhsoft.net> Date: Wed, 20 Sep 2017 19:30:44 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <75c3c518-56db-4887-99c7-32685e6e5f76@Spark> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-CH Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Consistent null behaviour From: lists@rhsoft.net ("lists@rhsoft.net") Am 20.09.2017 um 19:23 schrieb ilija.tovilo@me.com: > I realized after sending the initial E-Mail that there might be more > breaking changes than I thought, like the one you suggested. > > The same thing actually happens for bools, ints and floats: > https://3v4l.org/jvVbO > > I wouldn’t depend on this behaviour since you’d get errors depending on > what is returned, like an empty array, a string, an object or resource. i would depend on that behavior because in reality you can get back two different things: * a numeric array with exactly index 0 * NULL how do you imagine mysqli_fetch_row() return empty array, string or even object/resource? when nothing is found it's a non-empty array and otherwise NULL before PHP 5.6 (or PHP 5.5 not sure) these where useless multiple lines because you needed to store the result of mysqli_fetch_row() in some var to access key 0 > On 20 Sep 2017, 19:18 +0200, lists@rhsoft.net , wrote: >> >> >> Am 20.09.2017 um 19:06 schrieb ilija.tovilo@me.com: >>> Hi everybody! >>> >>> To my surprise, I noticed today that an array access on a `null` >>> value returns `null` without any warning whatsoever. >>> Accessing the property of a `null` value gives you a notice, while >>> calling a function on that `null` value gives you a fatal error. >>> >>> https://3v4l.org/ZSZHN >>> >>> This is pretty inconsistent. IMO all of these should be fatal errors, >>> although I realize that might be a bit drastic for PHP 8. >>> We should at least give the user a notice when using array access on >>> a `null` value. >>> >>> Any thoughts? >> wouldn't that break code like below which is IMHO the best usecase of >> the PHP 5.6 feature that you can directly access a array field of a >> function result and the type-casting encsues that the return-type is >> always int >> >> function GetSKatMaxSort(int $archive=0): int >> { >> return (int)mysqli_fetch_row($this->db->query("select SQL_NO_CACHE >> max(ssort) from {$this->db->table} where sarchive=$archive", 1))[0]; >> }