xref: /PHP-5.3/tests/classes/class_example.phpt (revision c3fddcab)
1--TEST--
2Classes general test
3--FILE--
4
5<?php
6
7/* pretty nifty object oriented code! */
8
9class user {
10  public $first_name,$family_name,$address,$phone_num;
11  function display()
12  {
13    echo "User information\n";
14    echo "----------------\n\n";
15    echo "First name:\t  ".$this->first_name."\n";
16    echo "Family name:\t  ".$this->family_name."\n";
17    echo "Address:\t  ".$this->address."\n";
18    echo "Phone:\t\t  ".$this->phone_num."\n";
19    echo "\n\n";
20  }
21  function initialize($first_name,$family_name,$address,$phone_num)
22  {
23    $this->first_name = $first_name;
24    $this->family_name = $family_name;
25    $this->address = $address;
26    $this->phone_num = $phone_num;
27  }
28};
29
30
31function test($u)
32{  /* one can pass classes as arguments */
33  $u->display();
34  $t = $u;
35  $t->address = "New address...";
36  return $t;  /* and also return them as return values */
37}
38
39$user1 = new user;
40$user2 = new user;
41
42$user1->initialize("Zeev","Suraski","Ben Gourion 3, Kiryat Bialik, Israel","+972-4-8713139");
43$user2->initialize("Andi","Gutmans","Haifa, Israel","+972-4-8231621");
44$user1->display();
45$user2->display();
46
47$tmp = test($user2);
48$tmp->display();
49
50?>
51--EXPECT--
52User information
53----------------
54
55First name:	  Zeev
56Family name:	  Suraski
57Address:	  Ben Gourion 3, Kiryat Bialik, Israel
58Phone:		  +972-4-8713139
59
60
61User information
62----------------
63
64First name:	  Andi
65Family name:	  Gutmans
66Address:	  Haifa, Israel
67Phone:		  +972-4-8231621
68
69
70User information
71----------------
72
73First name:	  Andi
74Family name:	  Gutmans
75Address:	  Haifa, Israel
76Phone:		  +972-4-8231621
77
78
79User information
80----------------
81
82First name:	  Andi
83Family name:	  Gutmans
84Address:	  New address...
85Phone:		  +972-4-8231621
86