03/03_staticpA.php


  1  <html>
  2  <body>
  3  <?php
  4  
  5  class CA
  6  {
  7    protected  $x="?";
  8    protected static $p="??";
  9    public function CA($x)
 10    {
 11      $this->x=$x;
 12      echo "CA::CA($x)<br />\r\n";
 13    }
 14    public function __set($meno,$hodnota)
 15    {
 16      print("Nastavované: \$$this->x->$meno=$hodnota<br />\n");
 17      $this->$meno = $hodnota;
 18    }
 19  }
 20  
 21  $A = new CA("A");
 22  $B = new CA("B");
 23  
 24  $A->p="Kuk";  // Fatal error: Cannot access protected property CA::$p in C:\!IB\Projekty\PHP\5\03\03_staticpA.php on line 24
 25  $B->p="Juj";
 26  CA::$p="Bum";
 27  
 28  echo "\$A->p=$A->p<br />\r\n";
 29  echo "\$B->p=$B->p<br />\r\n";
 30  echo "CA::\$p=".CA::$p."<br />\n";
 31  
 32  ?>
 33  </body>
 34  </html>

« Spä¯