Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72995 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76463 invoked from network); 7 Mar 2014 16:12:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Mar 2014 16:12:52 -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.43 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 74.125.82.43 mail-wg0-f43.google.com Received: from [74.125.82.43] ([74.125.82.43:62687] helo=mail-wg0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 31/23-57079-200F9135 for ; Fri, 07 Mar 2014 11:12:51 -0500 Received: by mail-wg0-f43.google.com with SMTP id x13so5292699wgg.14 for ; Fri, 07 Mar 2014 08:12:47 -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=Sh7hk8CetRHITnKCRPGg3SH0VzH14hxqS0vcaKsbmxU=; b=XgVfqpjiCkjZezugHFZVel1kQUBpWQL1K/kgCQZdB5moCuodEBfgTDrGYExkRSAgSv lYBJi0201dNamPtAyI8vreDHn41zJGr2NFF3mTd3OUX88qvVl3zxpncxoHAektK+32Hj RbhnnPf6INeUb2Kbi98C0zdChup6Jb5KFGiwMg/NTfewW/578WUniy10RPaj9+19mz2Y 0yPoWtaYhXMe7ZHd7Hm7ek0MtKdgXSsq3XULrfjb44qq/SA6cZUCQ2M2RxV3SVd1ADzK ahL4ROoFs412TZfVnYAgS57MEnxLnYoO2FKSVqSKur0y7s+9AH2cOxV9CG4XhjXcwPMh 1Epw== X-Received: by 10.194.234.106 with SMTP id ud10mr20879444wjc.0.1394208767141; Fri, 07 Mar 2014 08:12:47 -0800 (PST) MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.216.47.67 with HTTP; Fri, 7 Mar 2014 08:12:17 -0800 (PST) In-Reply-To: References: Date: Fri, 7 Mar 2014 17:12:17 +0100 X-Google-Sender-Auth: CDL9zCwM66hdPARs8ZLNdk-K4tM Message-ID: To: Julien Pauli Cc: Tjerk Meesters , PHP Internals Content-Type: multipart/alternative; boundary=089e014940784eecc004f4068689 Subject: Re: [PHP-DEV] [PR 614] ArrayObject and isset() / empty() behaviour From: colder@php.net (Etienne Kneuss) --089e014940784eecc004f4068689 Content-Type: text/plain; charset=UTF-8 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 --089e014940784eecc004f4068689--