Annotation of embedaddon/php/tests/classes/class_example.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Classes general test
3: --FILE--
4:
5: <?php
6:
7: /* pretty nifty object oriented code! */
8:
9: class 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:
31: function 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--
52: User information
53: ----------------
54:
55: First name: Zeev
56: Family name: Suraski
57: Address: Ben Gourion 3, Kiryat Bialik, Israel
58: Phone: +972-4-8713139
59:
60:
61: User information
62: ----------------
63:
64: First name: Andi
65: Family name: Gutmans
66: Address: Haifa, Israel
67: Phone: +972-4-8231621
68:
69:
70: User information
71: ----------------
72:
73: First name: Andi
74: Family name: Gutmans
75: Address: Haifa, Israel
76: Phone: +972-4-8231621
77:
78:
79: User information
80: ----------------
81:
82: First name: Andi
83: Family name: Gutmans
84: Address: New address...
85: Phone: +972-4-8231621
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>