04/02_staticd_x.php
1 <html>
2 <body>
3 <?php
4
5 class CA
6 {
7 public $x="?";
8 public static $p="??";
9 public function CA($x)
10 {
11 $this->x=$x;
12 echo "CA::CA($x)<br />\r\n";
13 }
14
15 public static function S ()
16 {
17 // echo "CA::S1: $this->x <br />\n"; // Chyba: Using $this when not in object context
18 echo "CA::S2:". self::$p." <br />\n";
19 echo "CA::S3:". CA::$p." <br />\n";
20 }
21
22 public function F ()
23 {
24 echo "CA::F1: $this->x <br />\n";
25 echo "CA::F2:". self::$p." <br />\n";
26 echo "CA::F3:". CA::$p." <br />\n";
27 }
28 }
29
30 class CB extends CA
31 {
32 public $x="?";
33 public function CB($x)
34 {
35 $this->x=$x;
36 echo "CB::CB($this->x)<br />\r\n";
37 }
38 }
39
40 echo "<b>Vytvorenie objektu \$A</b><br />\n";
41 $A = new CA("A");
42 CA::$p="Bum";
43 echo "<b>Volanie \$A->S()</b><br />\n";
44 $A->S();
45 echo "<b>Volanie \$A->F()</b><br />\n";
46 $A->F();
47 echo "<b>Volanie CA::S()</b><br />\n";
48 CA::S();
49 // echo "<b>Volanie CA::F()</b><br />\n";
50 // CA::F(); // Chyba: Using $this when not in object context
51
52 echo "<br /><b>Vytvorenie objektu \$B</b><br />\n";
53 $B = new CB("B");
54 CB::$p="Juj";
55 echo "<b>Volanie \$B->S()</b><br />\n";
56 $B->S();
57 echo "<b>Volanie \$B->F()</b><br />\n";
58 $B->F();
59 echo "<b>Volanie CB::S()</b><br />\n";
60 CB::S();
61
62 echo "<br /><b>Overenie hodnôt premenných</b><br />\n";
63 echo "\$A->x=$A->x CA::\$p=".CA::$p."<br />\n";
64 echo "\$B->x=$B->x CB::\$p=".CB::$p."<br />\n";
65
66 ?>
67 </body>
68 </html>