05/03_TestArg.php
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Author" content="Imrich BURANSKY" />
5 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1250" />
6 <title>TestArg</title>
7 </head>
8 <body>
9 <div>
10 <h2>Test argumenta</h2>
11 <?php
12
13 class CA
14 {
15 public function __construct()
16 {
17 echo "CA: Konštruktor<br />\n";
18 }
19
20 public function FA ()
21 {
22 echo "CA: Funkcia FA<br />\n";
23 }
24 }
25
26 class CB
27 {
28 public $A;
29 public function __construct($A)
30 {
31 echo "CB: Konštruktor<br />\n";
32 if (!($A instanceof CA)) die ("Chyba: \$A nie je inštanciou triedy CA");
33 $this->A = $A;
34 }
35
36 public function FB ()
37 {
38 echo "CB: Funkcia FB<br />\n";
39 }
40
41 public function FX ()
42 {
43 echo "CB: Funkcia FX<br />\n";
44 $this->A->FA();
45 }
46 }
47 echo "<b>Vytvorenie a použitie objektu triedy CB</b><br />\n";
48 $B = new CB(77); // V konštruktore CB skript "odumrie"
49
50 ?>
51 </div>
52 </body>
53 </html>