Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72998 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7792 invoked from network); 8 Mar 2014 00:27:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Mar 2014 00:27:49 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.182 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.220.182 mail-vc0-f182.google.com Received: from [209.85.220.182] ([209.85.220.182:45430] helo=mail-vc0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A9/F5-57079-3046A135 for ; Fri, 07 Mar 2014 19:27:47 -0500 Received: by mail-vc0-f182.google.com with SMTP id id10so4952265vcb.13 for ; Fri, 07 Mar 2014 16:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=5/NZZw0dFVbKltqLysYZOQ8unfGuzW38iWHLOOVyzqs=; b=VWq+q0vjF7gTeM59URJ5Nydvp79kAFQm+ijogZRVrX4FFPJfMTHv9m2bUnxMvJdgaD ANH9zIcjvA1ZavxQkZwS1jvxxGg+TZQ+JYkzWSBpbhwvZyJjOosjMiwA0t+0ELBp+7ba c1DL3c1rn0W4ssKMsPId6D+hYqVIPpKKAMRHJATjreM2HDfQ1rDTXePIcAL2amRez5Gs CGNZ5PCouj4ZImZvK2loNAtrpuv2M7CrPihIGF14vjES6Qn5uUHSIpIB9C1hK+Hyovy7 +VZnMiCIp1XkQ62JGUYeNSmdomYJ1idAqFJUPjYt/xzXvov2d5YtcIfumilGNBDDj+oh QwWg== MIME-Version: 1.0 X-Received: by 10.220.10.2 with SMTP id n2mr3446955vcn.26.1394238465093; Fri, 07 Mar 2014 16:27:45 -0800 (PST) Received: by 10.58.55.131 with HTTP; Fri, 7 Mar 2014 16:27:45 -0800 (PST) In-Reply-To: References: Date: Sat, 8 Mar 2014 08:27:45 +0800 Message-ID: To: Etienne Kneuss Cc: Julien Pauli , PHP Internals Content-Type: multipart/alternative; boundary=001a11c3a92071b61904f40d70a8 Subject: Re: [PHP-DEV] [PR 614] ArrayObject and isset() / empty() behaviour From: tjerk.meesters@gmail.com (Tjerk Meesters) --001a11c3a92071b61904f40d70a8 Content-Type: text/plain; charset=ISO-8859-1 Hi Etienne, Thanks for your input, much appreciated. I have moved the decision up the chain as you suggested; the results can be found here: https://github.com/datibbaw/php-src/compare/php:PHP-5.4...bug66834a It's suffering from a few memory leaks which can be fixed, but would this be acceptable otherwise? On Sat, Mar 8, 2014 at 12:12 AM, Etienne Kneuss wrote: > > > > On Fri, Mar 7, 2014 at 4:58 PM, Etienne Kneuss wrote: > >> >> >> 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. >> >> > Apart from this underlying "design" issue, it is true an overridden > version of ArrayObject is not functionally equivalent to the original > class. So it seems worth fixing independently from this hack. > -- > Etienne Kneuss > -- -- Tjerk --001a11c3a92071b61904f40d70a8--