Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73993 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5412 invoked from network); 7 May 2014 05:30:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 May 2014 05:30:07 -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.176 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.214.176 mail-ob0-f176.google.com Received: from [209.85.214.176] ([209.85.214.176:60414] helo=mail-ob0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 26/80-32043-ED4C9635 for ; Wed, 07 May 2014 01:30:07 -0400 Received: by mail-ob0-f176.google.com with SMTP id wo20so591389obc.7 for ; Tue, 06 May 2014 22:30:04 -0700 (PDT) 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=NPZTezmfdq3D7d+NNEPd1tbJs/yuy9/7Q38Oe63hI4s=; b=f7m3mDSUDyqBEHg1VU3s8wv9DwzU9mZ0kUjI+izojcPohogKR5JfTFknbsk1Gxmr+v mYLNvj6/eSiV3rJ9olZLe+jF1WGMXOvZ0EK5Fsv9ICKg/NqR/CxdzfPJE1dmUWBLz3C4 rFpvf2wLnMKkoldkVKc7KlPinCn2VMDoPOetmMJ3Of+dJQxvUkAi74/bl6uqUPj5ropo pNowH+j3AyAJ1YCNylqtmPhGQXu46CTVKCwN7q9atwbz/Un9dBZduG/oHlBbX8HhV9wm Vpj7BP4Py/khJiPfqBB3S5jY+IRhWx9R1rxDbNCSe6xsHaZ4OQSqMtcnrl7SUSEkk6m4 0lYw== MIME-Version: 1.0 X-Received: by 10.182.120.5 with SMTP id ky5mr41664568obb.11.1399440603050; Tue, 06 May 2014 22:30:03 -0700 (PDT) Received: by 10.76.77.100 with HTTP; Tue, 6 May 2014 22:30:02 -0700 (PDT) In-Reply-To: References: Date: Tue, 6 May 2014 23:30:02 -0600 Message-ID: To: Tjerk Anne Meesters Cc: Dmitry Stogov , Julien Pauli , PHP Internals Content-Type: multipart/alternative; boundary=089e012953d00777b504f8c8a84a Subject: Re: [PHP-DEV] Re: 5dee3c11 break From: morrison.levi@gmail.com (Levi Morrison) --089e012953d00777b504f8c8a84a Content-Type: text/plain; charset=UTF-8 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. 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; } --089e012953d00777b504f8c8a84a--