diff options
author | Nikita Popov <nikic@php.net> | 2016-03-20 13:33:00 +0100 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2016-03-20 13:35:00 +0100 |
commit | a175aa9dcaed5e295d015ff73c663e06c2335155 (patch) | |
tree | 41853e0a829967db7d4996448fcc50c29cc28cfa /Zend/tests/bug71731.phpt | |
parent | 1f6d27d3d2cf8a5113946a55a297441bb4c70ddf (diff) | |
download | php-git-a175aa9dcaed5e295d015ff73c663e06c2335155.tar.gz |
Fixed bug #71731
The read_dimension() handler in BP_VAR_IS mode will now call
offsetExists() before caling offsetGet(). This has always been a
problem, however recently the issue has been exacerbated, because
the null-coalesce operator ?? makes it visible for non-nested
array accesses.
Also fixes #69659.
Diffstat (limited to 'Zend/tests/bug71731.phpt')
-rw-r--r-- | Zend/tests/bug71731.phpt | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Zend/tests/bug71731.phpt b/Zend/tests/bug71731.phpt new file mode 100644 index 0000000000..46a79f1a34 --- /dev/null +++ b/Zend/tests/bug71731.phpt @@ -0,0 +1,64 @@ +--TEST-- +Bug #71731: Null coalescing operator and ArrayAccess +--FILE-- +<?php + +class AA implements ArrayAccess { + private $data = []; + public function offsetExists($name) { + echo "offsetExists($name)\n"; + return array_key_exists($name, $this->data); + } + public function &offsetGet($name) { + echo "offsetGet($name)\n"; + if (!array_key_exists($name, $this->data)) { + throw new Exception('Unknown offset'); + } + return $this->data[$name]; + } + public function offsetSet($name, $value) { + echo "offsetSet($name)\n"; + $this->data[$name] = $value; + } + public function offsetUnset($name) { + echo "offsetUnset($name)\n"; + unset($this->data[$name]); + } +} + +$aa = new AA; +var_dump(isset($aa[0][1][2])); +var_dump(isset($aa[0]->foo)); +var_dump($aa[0] ?? 42); +var_dump($aa[0][1][2] ?? 42); + +$aa[0] = new AA; +$aa[0][1] = new AA; +var_dump(isset($aa[0][1][2])); +var_dump($aa[0][1][2] ?? 42); + +?> +--EXPECT-- +offsetExists(0) +bool(false) +offsetExists(0) +bool(false) +offsetExists(0) +int(42) +offsetExists(0) +int(42) +offsetSet(0) +offsetGet(0) +offsetSet(1) +offsetExists(0) +offsetGet(0) +offsetExists(1) +offsetGet(1) +offsetExists(2) +bool(false) +offsetExists(0) +offsetGet(0) +offsetExists(1) +offsetGet(1) +offsetExists(2) +int(42) |