[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Dolibarr-dev] Error in invoice clone

From: Sébastien
Subject: Re: [Dolibarr-dev] Error in invoice clone
Date: Wed, 04 Sep 2013 09:32:32 +0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130803 Thunderbird/17.0.8


I use PHP 5.4.6-1ubuntu1.3  on my dev computer and  PHP 5.3.3-7+squeeze17 on production server.

In php doc :

One of the key-points of PHP 5 OOP that is often mentioned is that "objects are passed by references by default".
When an object is cloned, PHP 5 will perform a shallow copy of all of the object's properties. Any properties that are references to other variables, will remain references.

this->lines is an array of object created by "=" operator, it's a reference.
(See exemple 1 in cloning manual page)

Le 03/09/2013 20:48, Destailleur Laurent a écrit :
Also, do you have an idea why this fails (copy by value) for property this->lines and not all other ?

Le 3 septembre 2013 18:44, Destailleur Laurent <address@hidden> a écrit :
Which version of PHP do you use ?

2013/9/3 Sébastien <address@hidden>

When i clone invoice with object in htdocs/compta/facture/class/facture.class.php the invoice lines aren't cloned.
The clone lines are referenced from origin invoice.
Add this function to class Facture (~ line 129) :

function __clone()
        // Force a copy of this->lines, otherwise it will point to same object.
        for($i=0; $i < count($this->lines); $i++){
            $this->lines[$i] = clone $this->lines[$i];

In french :
Lorsque l'on clone une facture via la classe facture dans compta (fichier htdocs/compta/facture/class/facture.class.php), les lignes de la facture ne sont pas clonés mais simplement copiées par référence.
Il suffit d'ajouter la fonction pour cloner les lignes et cela fonctionne !
Probléme constaté sur la version 3.3.1 et a l'air d'être toujours présent dans la version 3.4.0


Dolibarr-dev mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]