Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73994 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7065 invoked from network); 7 May 2014 05:31:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 May 2014 05:31:25 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.169 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.214.169 mail-ob0-f169.google.com Received: from [209.85.214.169] ([209.85.214.169:33297] helo=mail-ob0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 93/E0-32043-825C9635 for ; Wed, 07 May 2014 01:31:24 -0400 Received: by mail-ob0-f169.google.com with SMTP id vb8so597475obc.14 for ; Tue, 06 May 2014 22:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=wiKnBm85L7JCDmhoKGJArLiHjUcLa6trPqR1jWffUAM=; b=kbLGyr9QXOaB/yaUyI0/PVqo9V0Cl9vRey4VBlot9mhUEXyl83AKWlCqdUzKS+bQES o/ZOS5FSNvxnxTXB/7bL+m3nln4PlwZdIPU67Uj4/hBWRR5mKT1W9VPvcghKs400AlqQ DUAwXrtGuLmYbInKyYHTw344pj9J8YDY7kC70eOsufA4PNtsB5pahWAhnhZXdR49Ghwi KMU3eD4leZgs7PN/nYvUvB1LvWO8EeeBsvdZ69hLm1kEk2WoD/KsqQyR/dTL51511yRI vOYDCZdHoNO0v9+IQjFQk9ubDAMrnKwVohgD2ortJm5cltQ9XEiLw9PJIv8IBmENnyQU FU2w== MIME-Version: 1.0 X-Received: by 10.182.95.10 with SMTP id dg10mr6312252obb.65.1399440672914; Tue, 06 May 2014 22:31:12 -0700 (PDT) Sender: morrison.levi@gmail.com Received: by 10.76.77.100 with HTTP; Tue, 6 May 2014 22:31:12 -0700 (PDT) In-Reply-To: References: Date: Tue, 6 May 2014 23:31:12 -0600 X-Google-Sender-Auth: 1Aw9RkSmOK5M0xObM7LL9M4NCTA Message-ID: To: Tjerk Anne Meesters Cc: Dmitry Stogov , Julien Pauli , PHP Internals Content-Type: multipart/alternative; boundary=089e0158acc432728204f8c8ac99 Subject: Re: [PHP-DEV] Re: 5dee3c11 break From: levim@php.net (Levi Morrison) --089e0158acc432728204f8c8ac99 Content-Type: text/plain; charset=UTF-8 On Tue, May 6, 2014 at 11:30 PM, Levi Morrison wrote: > I think perhaps I haven't been clear in the past posts; I apologize. The > basic premise is that `isset` and `empty` should work the same on arrays as > they do on any array object. The problem comes from the fact that > `offsetExists` does not say that you should return false for an existing > offset with a null value. > > At the end of this email is is a gauntlet of tests that *should work*, the > only exception is ExtendedArrayAccess which returns true for an existing > key with a null value (uses array_key_exists). I'd argue that > ExtendedArrayAccess uses the correct semantics and that all others should > be changed to not do the null check (only does it exist) but that would be > a big BC break. Hopefully this all makes sense. > > > class ExtendedArrayObject extends ArrayObject { > function offsetExists($offset) { > //echo "\t", __METHOD__, PHP_EOL; > return parent::offsetExists($offset); > } > function offsetGet($offset) { > //echo "\t", __METHOD__, PHP_EOL; > return parent::offsetGet($offset); > } > } > > class ExtendedArrayAccess implements ArrayAccess { > private $data = array(); > function __construct(array $array = array()) { > $this->data = $array; > } > function offsetExists($offset) { > return array_key_exists($offset, $this->data); > } > function offsetGet($offset) { > return $this->data[$offset]; > } > function offsetSet($offset, $value) { > $this->data[$offset] = $value; > } > function offsetUnset($offset) { > unset($this->data[$offset]); > } > } > > function createInputs() { > return array( > array(), > new ArrayObject(), > new ExtendedArrayObject(), > new ExtendedArrayAccess(), > ); > } > > class Tests { > function isset_existing_key_with_not_empty_value($array) { > $array['foo'] = 1; > $this->expect(isset($array['foo']) === true, $array); > } > > function empty_existing_key_with_not_empty_value($array) { > $array['foo'] = 1; > $this->expect(empty($array['foo']) === false, $array); > } > > function isset_existing_key_with_empty_value($array) { > $array['foo'] = 0; > $this->expect(isset($array['foo']) === true, $array); > } > > function empty_existing_key_with_empty_value($array) { > $array['foo'] = 0; > $this->expect(empty($array['foo']) === true, $array); > } > > function isset_non_existent_key($array) { > $this->expect(isset($array['foo']) === false, $array); > } > > function empty_non_existent_key($array) { > $this->expect(empty($array['foo']) === true, $array); > } > > function isset_existing_key_with_null_value($array) { > $array['foo'] = null; > $this->expect(isset($array['foo']) === false, $array); > } > > function empty_existing_key_with_null_value($array) { > $array['foo'] = null; > $this->expect(empty($array['foo']) === true, $array); > } > > private function getType($v) { > return is_array($v) ? 'array' : get_class($v); > } > > private function expect($condition, $array) { > if (!$condition) { > echo "\t", $this->getType($array), ' failed ', PHP_EOL; > } > } > } > > $tests = new Tests; > foreach (get_class_methods($tests) as $test) { > echo "$test:", PHP_EOL; > foreach (createInputs() as $structure) { > $tests->$test($structure); > } > echo PHP_EOL; > } > > Here it is on 3v4l: http://3v4l.org/SoFnK --089e0158acc432728204f8c8ac99--