コード例 #1
0
$obj01->_attribut1 = 'Hi my friend<br>';
echo $obj02->_attribut1;
// Return 'Hi my friend'
$obj02->_attribut2 = 'Bonjour mon pote<br>';
echo $obj01->_attribut2;
// Return 'Bonjour mon pote'
// Je copie l'objet et je crée ainsi un nouvel objet
// Un nouvel identifiant est créé - chaque objet à son propre identifiant
// Chaque objet peut gérer de nouveaux attributs sans intervenir sur les anciens attributs
$copieObject = clone $obj01;
$obj01->_attribut1 = 'New phrase<br>';
echo $copieObject->_attribut1;
// Return Hi my friend et non New Phrase
echo $obj01->_attribut1;
// Retrun 'New phrase'
echo 'Nombre d\'instances de MyClass : ' . My_Class::getCountInstances() . '<br>';
?>
                </p>
                
                
                <h2>Exemple 2 - Comparaison d'objets</h2>
                <p class="col-sm-12">
                    <?php 
// Exemple 1
class My_Class_2
{
    public $_attribut1;
    public $_attribut2;
}
class My_Class_3
{