Skip to content

Commit 848f9c3

Browse files
committed
Preserve backwards compatibility of Ast\Node::toArray(): do shallow conversion by default
1 parent 835e4e6 commit 848f9c3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Language/AST/Node.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,26 @@ private function cloneValue($value)
8181
*/
8282
public function __toString()
8383
{
84-
$tmp = $this->toArray();
84+
$tmp = $this->toArray(true);
8585
return json_encode($tmp);
8686
}
8787

8888
/**
89+
* @param bool $recursive
8990
* @return array
9091
*/
91-
public function toArray()
92+
public function toArray($recursive = false)
9293
{
9394
$tmp = (array) $this;
95+
9496
$tmp['loc'] = [
9597
'start' => $this->loc->start,
9698
'end' => $this->loc->end
9799
];
98100

99-
$this->recursiveToArray($tmp);
101+
if ($recursive) {
102+
$this->recursiveToArray($tmp);
103+
}
100104

101105
return $tmp;
102106
}
@@ -108,7 +112,7 @@ public function recursiveToArray(&$object)
108112
{
109113
if ($object instanceof Node) {
110114
/** @var Node $object */
111-
$object = $object->toArray();
115+
$object = $object->toArray(true);
112116
} elseif (is_object($object)) {
113117
$object = (array) $object;
114118
} elseif (is_array($object)) {

0 commit comments

Comments
 (0)