From c2c25ada84d07fab4dca6d6e6f9ae1b54fee070a Mon Sep 17 00:00:00 2001 From: orklah Date: Wed, 6 Jan 2021 15:44:12 +0100 Subject: [PATCH] add ArrayAccess to SimpleXmlElement (#4934) * add ArrayAccess to SimpleXmlElement * add test --- stubs/CoreGenericClasses.phpstub | 18 +++++++++++++++++- tests/ArrayAccessTest.php | 8 ++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/stubs/CoreGenericClasses.phpstub b/stubs/CoreGenericClasses.phpstub index 8af9c4291..8a8b8d98f 100644 --- a/stubs/CoreGenericClasses.phpstub +++ b/stubs/CoreGenericClasses.phpstub @@ -2215,7 +2215,7 @@ final class WeakReference public function get(): ?object; } -class SimpleXMLElement implements \Stringable, \Countable, \RecursiveIterator +class SimpleXMLElement implements \Stringable, \Countable, \RecursiveIterator, \ArrayAccess { /** @return array */ public function getNamespaces(bool $recursive = false) @@ -2284,6 +2284,22 @@ class SimpleXMLElement implements \Stringable, \Countable, \RecursiveIterator public function getChildren() { } + + public function offsetExists($offset) + { + } + + public function offsetGet($offset) + { + } + + public function offsetSet($offset, $value) + { + } + + public function offsetUnset($offset) + { + } } interface Serializable { diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index e8314ff20..cf09a415d 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -835,6 +835,14 @@ class ArrayAccessTest extends TestCase return $s["a"]; }', ], + 'simpleXmlArrayFetchChildren' => [ + 'children() as $img) { + yield $img["src"] ?? ""; + } + }', + ], 'assertOnArrayAccess' => [ '