Skip to content

Commit

Permalink
Fix php issue with cloning an object that has a reference to one of i…
Browse files Browse the repository at this point in the history
…t's data members
  • Loading branch information
alexey-pkv committed Jul 31, 2017
1 parent c5500a6 commit 42763b9
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Objection/LiteObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ abstract class LiteObject
/** @var array */
private $values;

private $ignoreSet;


/** @var static */
protected $_p;
Expand Down Expand Up @@ -150,6 +152,12 @@ public function &__get($name)
*/
public function __set($name, $value)
{
if ($this->ignoreSet)
{
$this->$name = $value;
return;
}

$this->validateFieldAccess($name, AccessRestriction::NO_SET);

$value = ValueValidation::fixValue($this->data[$name], $value);
Expand All @@ -175,7 +183,20 @@ public function __debugInfo()
return $this->values;
}


public function __clone()
{
$values = $this->values;

unset($this->values);
unset($this->_p);

$this->ignoreSet = true;
$this->values = unserialize(serialize($values));
$this->_p = new PrivateFields($this->values, $this->data, $this);
$this->ignoreSet = false;
}


/**
* @param LiteObject[] $objects
* @param array $filter
Expand Down

0 comments on commit 42763b9

Please sign in to comment.