04/03_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 parent::$x="rodicovske x"; // Chyba: Access to undeclared static property
37 echo "CB::CB($this->x)<br />\r\n";
38 }
39 }
40
41 echo "<b>Vytvorenie objektu \$A</b><br />\n";
42 $A = new CA("A");
43 CA::$p="Bum";
44 echo "<b>Volanie \$A->S()</b><br />\n";
45 $A->S();
46 echo "<b>Volanie \$A->F()</b><br />\n";
47 $A->F();
48 echo "<b>Volanie CA::S()</b><br />\n";
49 CA::S();
50 // echo "<b>Volanie CA::F()</b><br />\n";
51 // CA::F(); // Chyba: Using $this when not in object context
52
53 echo "<br /><b>Vytvorenie objektu \$B</b><br />\n";
54 $B = new CB("B");
55 CB::$p="Juj";
56 echo "<b>Volanie \$B->S()</b><br />\n";
57 $B->S();
58 echo "<b>Volanie \$B->F()</b><br />\n";
59 $B->F();
60 echo "<b>Volanie CB::S()</b><br />\n";
61 CB::S();
62
63 echo "<br /><b>Overenie hodnôt premenných</b><br />\n";
64 echo "\$A->x=$A->x CA::\$p=".CA::$p."<br />\n";
65 echo "\$B->x=$B->x CB::\$p=".CB::$p."<br />\n";
66
67 ?>
68 </body>
69 </html>