PHP       WEB       3GL   4GL   5GL      

PHP 2

, , . , , .

, PHP , construct. . ? -. , , , - (- , , - ). , - . . - , .. .

, , , , , . , . , unset(). , , , - , .

, . . PHP , destruct (__destruct):

1<?php
2class Users{
3    public $name;
4    public $login;
5    public $password;
6     
7    //
8    function __construct($number){
9        echo "<p> $number!";
10    }
11     
12    //
13    function __destruct(){
14        echo "<p> !";
15    }
16     
17    // getInfo()
18    function getInfo(){
19        echo "<p>Name: ".$this->name."<br>";
20        echo "Login: ".$this->login."<br>";
21        echo "Password: ".$this->password."<br>";
22    }
23}
24 
25$user1 = new Users(1);
26    $user1->name = "Vasya";
27    $user1->login = "vas";
28    $user1->password = 123;
29    // getInfo()
30    $user1->getInfo();
31 
32$user2 = new Users(2);
33    $user2->name = "Petya";
34    $user2->login = "pet";
35    $user2->password = 321;
36    // getInfo()
37    $user2->getInfo();
38 
39$user3 = new Users(3);
40    $user3->name = "Vova";
41    $user3->login = "vov";
42    $user3->password = 456;
43    // getInfo()
44    $user3->getInfo();
45?>

, , , , - . - - " !".

, , ! - , . . , . - , , .

, , :

  1. Users ;
  2. name, login, password;
  3. , Users;

:

1<?php
2class Users{
3    public $name;
4    public $login;
5    public $password;
6     
7    //
8    function __construct($name, $login, $password){
9        $this->name = $name;
10        $this->login = $login;
11        $this->password = $password;
12    }
13     
14    // getInfo()
15    function getInfo(){
16        echo "<p>Name: ".$this->name."<br>";
17        echo "Login: ".$this->login."<br>";
18        echo "Password: ".$this->password."<br>";
19    }
20}
21 
22$user1 = new Users("Vasya", "vas", "123");
23    // getInfo()
24    $user1->getInfo();
25 
26$user2 = new Users("Petya", "pet", "321");
27    // getInfo()
28    $user2->getInfo();
29 
30$user3 = new Users("Vova", "vov", "456");
31    // getInfo()
32    $user3->getInfo();
33?>

4 PHP, , . , . , , Users, Users (function Users(){}). .

- , . ? : $object2 = $object1. , , ? , ? . ? , PHP - 4 5. 4 PHP . 2 - 1. , - $object2 = &$object1. - ? , , windows - . . , . 4 PHP.

5 ? $object2 = $object1 . , ? clone: $object2 = clone $object1.

, , . , - .

- clone (__clone), :

1<?php
2class Users{
3    public $name;
4    public $login;
5    public $password;
6     
7    //
8    function __construct($name, $login, $password){
9        $this->name = $name;
10        $this->login = $login;
11        $this->password = $password;
12    }
13     
14    // clone
15    function __clone(){
16        echo "<p> !";
17    }
18     
19    // getInfo()
20    function getInfo(){
21        echo "<p>Name: ".$this->name."<br>";
22        echo "Login: ".$this->login."<br>";
23        echo "Password: ".$this->password."<br>";
24    }
25}
26 
27$user1 = new Users("Vasya", "vas", "123");
28    // getInfo()
29    $user1->getInfo();
30 
31$user2 = new Users("Petya", "pet", "321");
32    // getInfo()
33    $user2->getInfo();
34 
35$user3 = new Users("Vova", "vov", "456");
36    // getInfo()
37    $user3->getInfo();
38// $user4 $user3
39$user4 = clone $user3;
40?>

:

  1. Users __clone();
  2. __clone ;
  3. : name = "User", login = "User", password = "qwerty";
  4. , ;

:

1<?php
2class Users{
3    public $name;
4    public $login;
5    public $password;
6     
7    //
8    function __construct($name, $login, $password){
9        $this->name = $name;
10        $this->login = $login;
11        $this->password = $password;
12    }
13     
14    // clone
15    function __clone(){
16        $this->name = "User";
17        $this->login = "User";
18        $this->password = "qwerty";
19    }
20     
21    // getInfo()
22    function getInfo(){
23        echo "<p>Name: ".$this->name."<br>";
24        echo "Login: ".$this->login."<br>";
25        echo "Password: ".$this->password."<br>";
26    }
27}
28 
29$user1 = new Users("Vasya", "vas", "123");
30    // getInfo()
31    $user1->getInfo();
32 
33$user2 = new Users("Petya", "pet", "321");
34    // getInfo()
35    $user2->getInfo();
36 
37$user3 = new Users("Vova", "vov", "456");
38    // getInfo()
39    $user3->getInfo();
40// $user4 $user3
41$user4 = clone $user3;
42    $user4->getInfo();
43?>
PHP       WEB       3GL   4GL   5GL         w  

, Polymorphism, - - , .




 21.01.2021 - 17:54: - Economy and Finances -> - _.
21.01.2021 - 08:17: , , - Upbringing, Inlightening, Education -> - _.
21.01.2021 - 07:59: , , - Upbringing, Inlightening, Education -> - _.
20.01.2021 - 17:39: , , - Upbringing, Inlightening, Education -> - _.
19.01.2021 - 12:55: - Conscience -> . ? - _.
18.01.2021 - 11:33: - Personalias -> WHO IS WHO - - _.
18.01.2021 - 09:05: , - War, Politics and Science -> . - _.
18.01.2021 - 08:21: , , - Upbringing, Inlightening, Education -> - _.
17.01.2021 - 17:59: , - War, Politics and Science -> - _.
17.01.2021 - 16:46: , , - Upbringing, Inlightening, Education -> - _.
17.01.2021 - 16:00: - Ecology -> - _.
15.01.2021 - 09:03: , - War, Politics and Science -> - _.
Bourabai Research -  XXI Bourabai Research Institution