mirror of
https://github.com/amphp/parallel.git
synced 2025-02-24 06:42:26 +01:00
Add handling for cloning local objects
This commit is contained in:
parent
712a4b69d2
commit
3855d8b5e9
@ -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.
|
||||
*
|
||||
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user