php - Explain Why This Happens Please -


i'm watching tutorial on oop php, , i've come constructor/destructor segment. when instantiate object, goes through constructor, deconstructs it.

here's code:

<?php    class person {      var $first_name;     var $last_name;      function __construct($firstname, $lastname) {        $this->first_name = $firstname;       $this->last_name = $lastname;        echo 'hi, name is: ' . $this->first_name . ' ' . $this->last_name . '!<br>';      }        function __destruct() {          echo "class objects being destroyed!<br>";        }    }    $person1 = new person('ringo', 'starr');   $person2 = new person('john', 'lennon');  ?> 

now when run code, echoes back:

hi, name is: ringo starr! hi, name is: john lennon! class objects being destroyed! class objects being destroyed! 

but, logically, @ least in mind, shouldn't code echo:

hi, name is: ringo starr! class objects being destroyed! hi, name is: john lennon! class objects being destroyed! 

since instantiate 1 object, goes through motions, creates new one? pretty inconsequential, want understand inner workings of programming.

thanks all.

<?php  //just explaination function funccontext() {//context exists     $person1 = new person('ringo', 'starr');     // person1 __constructed     //"hi, name is: ringo starr!"     //alive      $person2 = new person('john', 'lennon');     // person2 __constructed     // "hi, name is: john lennon!"     // alive      //they remain alive till context  }//context destroyed //they destroyed //"class objects being destroyed!" //"class objects being destroyed!" 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -