·  PHP – Syntax – OOP – Terms – Object Cloning


- Info:

  - From PHP 5 all Objects are treated by default as references which allows use of design patterns.

  - To copy object you have to clone it by prefacing it with the clone keyword, like so:


- Single File:

  - This example shoes efects of referencing and cloning.

  - Creat PHP Console Application Test.php.






      class Person {

        public $name = "John";




      $john = new Person();



      $jack = clone $john;

      $jack->name = "Jill"//This will not change $john->name

      echo($john->name);     //John



      $jill = $john;         //Jill is only reference to john.

      $jill->name = "Jill"//This also changes $john->name

      echo($john->name);     //Jill