Skip to content

Commit 890da9c

Browse files
committed
Clone any object used in search criteria.
Without cloning, objects with array access end up being modified.
1 parent 7125c6c commit 890da9c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/HasModelDataTrait.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public function get(string $key, $default = null)
4545
return data_get($this->data, $key, $default);
4646
}
4747

48+
public function __get($name)
49+
{
50+
return $this->get($name);
51+
}
52+
4853
public function jsonSerialize()
4954
{
5055
return $this->data;

src/OdooClient.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public function nullValue()
265265
* @param int $offset
266266
* @param int $limit
267267
* @param string $order comma-separated list of fields
268-
* @return Response
268+
* @return mixed
269269
*/
270270
public function search(
271271
string $modelName,
@@ -917,6 +917,16 @@ public function nativeToValue($item)
917917

918918
// If an iterable, then deal with the children first.
919919

920+
// Clone the item if it is an object.
921+
// If we don't, then collections get changed in-situ, i.e. your
922+
// collection of IDs submitted for the criteria is converted to
923+
// XML-RPC Value objects.
924+
// Arrays are automatically cloned by PHP on first change.
925+
926+
if (is_object($item)) {
927+
$item = clone($item);
928+
}
929+
920930
foreach ($item as $key => $element) {
921931
$item[$key] = $this->nativeToValue($element);
922932
}

0 commit comments

Comments
 (0)