Hi

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 : http://www.php.net/manual/en/language.oop5.references.php
and http://php.net/manual/en/language.oop5.cloning.php

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 <e...@destailleur.fr <mailto:e...@destailleur.fr>> a écrit :

    Which version of PHP do you use ?


    2013/9/3 Sébastien <seb-mail...@itoi.fr <mailto:seb-mail...@itoi.fr>>

        Hi,

        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

        Cordialement,
        Sébastien


        _______________________________________________
        Dolibarr-dev mailing list
        Dolibarr-dev@nongnu.org <mailto:Dolibarr-dev@nongnu.org>
        https://lists.nongnu.org/mailman/listinfo/dolibarr-dev




_______________________________________________
Dolibarr-dev mailing list
Dolibarr-dev@nongnu.org
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev

Répondre à