Add handling for cloning local objects

This commit is contained in:
coderstephen 2015-08-05 11:19:48 -05:00
parent 712a4b69d2
commit 3855d8b5e9
2 changed files with 20 additions and 0 deletions

View File

@ -114,6 +114,16 @@ class LocalObject implements \Serializable
}
}
/**
* Handles cloning, which creates clones the local object and creates a new
* local object handle.
*/
public function __clone()
{
$object = clone $this->deref();
$this->__construct($object);
}
/**
* Gets information about the object for debugging purposes.
*

View File

@ -91,4 +91,14 @@ class LocalObjectTest extends TestCase
$thread->start(PTHREADS_INHERIT_INI);
$thread->join();
}
public function testCloneIsNewObject()
{
$object = new \stdClass();
$local = new LocalObject($object);
$clone = clone $local;
$this->assertNotSame($local, $clone);
$this->assertNotSame($object, $clone->deref());
$this->assertNotEquals($local->__debugInfo()['id'], $clone->__debugInfo()['id']);
}
}