PHP/Class/Properties get — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 13:37, 26 мая 2010

Properties get Demo

   <source lang="html4strict">

<?php class Person {

   function __get( $property ) {
       $method = "get{$property}";
       if ( method_exists( $this, $method ) ) {
           return $this->$method();
       }
   }
                                                                               
   function getName() {
       return "Joe";
   }
                                                                               
   function getAge() {
       return 31;
   }

} $p = new Person(); print $p->name; ?>


      </source>