Skip to content

Commit

Permalink
Implementing the __clone() method with the
Browse files Browse the repository at this point in the history
proper model dereferencing logic
  • Loading branch information
Rican7 committed Jun 6, 2016
1 parent 9faa478 commit 2cd7129
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ public function __toString()
return $this->format();
}

/**
* Handle PHP object `clone`.
*
* This makes sure that the object doesn't still flag an attached model as
* dirty after cloning the DateTime object and making modifications to it.
*
* @return void
*/
public function __clone()
{
$this->model = null;
$this->attribute_name = null;
}

private function flag_dirty()
{
if ($this->model)
Expand Down

0 comments on commit 2cd7129

Please sign in to comment.