mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 01:28:19 +01:00
Fix clone function
This commit is contained in:
@@ -624,18 +624,26 @@ function dol_buildpath($path, $type=0)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a clone of instance of object (new instance with same value for properties)
|
* Create a clone of instance of object (new instance with same value for properties)
|
||||||
* Property that are reference are also new object (true clone)
|
* With native = 0: Property that are reference are also new object (true clone). This means $this->db is not valid.
|
||||||
|
* With native = 1: Use PHP clone. Property that are reference are same pointer. This means $this->db is still valid.
|
||||||
*
|
*
|
||||||
* @param object $object Object to clone
|
* @param object $object Object to clone
|
||||||
|
* @param int $native Native method or true method
|
||||||
* @return object Object clone
|
* @return object Object clone
|
||||||
* @see https://php.net/manual/language.oop5.cloning.php
|
* @see https://php.net/manual/language.oop5.cloning.php
|
||||||
*/
|
*/
|
||||||
function dol_clone($object)
|
function dol_clone($object, $native=0)
|
||||||
{
|
{
|
||||||
//dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);
|
//dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);
|
||||||
|
|
||||||
//$myclone = clone $object; // PHP clone is a shallow copy only, not a real clone, so properties of references will keep references (refer to the same target/variable
|
if (empty($native))
|
||||||
$myclone=unserialize(serialize($object));
|
{
|
||||||
|
$myclone=unserialize(serialize($object));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$myclone = clone $object; // PHP clone is a shallow copy only, not a real clone, so properties of references will keep references (refer to the same target/variable)
|
||||||
|
}
|
||||||
|
|
||||||
return $myclone;
|
return $myclone;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user