Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72994 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74563 invoked from network); 7 Mar 2014 15:59:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Mar 2014 15:59:26 -0000 Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.182 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 74.125.82.182 mail-we0-f182.google.com Received: from [74.125.82.182] ([74.125.82.182:42821] helo=mail-we0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CC/B2-57079-CDCE9135 for ; Fri, 07 Mar 2014 10:59:25 -0500 Received: by mail-we0-f182.google.com with SMTP id p61so5150294wes.13 for ; Fri, 07 Mar 2014 07:59:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=KTUv1eSTvQyqxpphr2HtmtgRi1Mhl/ui2qZH3oH1TQA=; b=f0xYOFjr9wlRCF2tO1xKyktKeiOYflvOMoXxD3xNbNG0ADe7uV23JcSyVpbe0JyGmY Y6oE0ut/d7DtTQjLaO8H3sgYlVpWjduEbZ0Ge3lQqkm6G6aoX0YiV5fcw1V0NcC4hYiS zEGM2Rlmj/zW7IswJaHpzCtO+1Tf4TStkxhrpBVbOz5WRV9JsV5vHlzKA9SSvrjut3tH gPiREuhRm4aGf+ciTXK+Q5i3ismknUd3OnfkcljV/+LvTvcWGy94I9fDfd4R8MeInrbh JWvvu7AmJEaTMwmDGj5FGDvgz3pnhx/LV50KgMNaB5OhkZLMrDRzwFE566GWURu1fdl9 P9uA== X-Received: by 10.194.234.106 with SMTP id ud10mr20769172wjc.0.1394207962088; Fri, 07 Mar 2014 07:59:22 -0800 (PST) MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.216.47.67 with HTTP; Fri, 7 Mar 2014 07:58:51 -0800 (PST) In-Reply-To: References: Date: Fri, 7 Mar 2014 16:58:51 +0100 X-Google-Sender-Auth: r68o-ECKwA0zJ1zRnXJRW3jPipE Message-ID: To: Julien Pauli Cc: Tjerk Meesters , PHP Internals Content-Type: multipart/alternative; boundary=089e0149407852cfb904f40656a2 Subject: Re: [PHP-DEV] [PR 614] ArrayObject and isset() / empty() behaviour From: colder@php.net (Etienne Kneuss) --089e0149407852cfb904f40656a2 Content-Type: text/plain; charset=UTF-8 On Fri, Mar 7, 2014 at 3:15 PM, Julien Pauli wrote: > On Fri, Mar 7, 2014 at 11:14 AM, Tjerk Meesters > wrote: > > Hi, > > > > I come across the following bug: https://bugs.php.net/bug.php?id=66834 > > > > With an extended ArrayObject instance, the behaviour of `isset()` and > > `empty()` is as follows: > > > > 1. Call `static::offsetExists()` > > 2. If return value is truthy, then > > a. isset() returns true > > b. empty() returns false > > c. spl_array_has_property() returns true > > > > However, if the ArrayObject instance is not overridden: > > > > 1. Fetch value (either via string or long key) > > 2. If key is found, then: > > a. isset() returns false if value is `null`, true otherwise. > > b. empty() returns true if value is truty, false otherwise. > > c. spl_array_has_property() returns true > > > > That's counterintuitive, so my patch addresses this by also calling > > `offsetGet()` if applicable. I wanted to bring this to the attention of > the > > group first, because it may affect performance to achieve this goal: > I have always been annoyed by this dichotomy between offsetExists() which is functionning like array_key_exists() and isset() which is returning false on defined, null values. Especially since isset() calls offsetExists() only. I would argue that the correct way to fix it is to have isset()/empty() call offsetGet() as well if it exists. So in that sense I feel like your patch is not addressing the right issue. In a sense ArrayObject does a hack to circumvent that in the first place, and you are trying to fix the hack to make it look more like what is supposed to happen. -- Etienne Kneuss --089e0149407852cfb904f40656a2--