php一些魔术方法简单说明

//$str = "我想要找空格之后的字符串是 我是空格之后的字符串";

//$preg = "/.*\s(.*)/i";

//preg_match($preg,$str,$arr);

//echo $arr[1];

class Add extends Person

{

public function su(){

return 22;

}

}

    class Person 

    { 

private static $pstn;

public function __construct()

{

//self::$zgFunc = self::getCommonFunction();

}

        public function __get($uu) 

        { 


//echo strtolower($property_name);

            if(isset($this->$uu)) 

            { 

              // return ($this->$property_name); 

            } 

            else 

            { 

                //return (NULL); 

            } 

echo $this->$uu;

echo $this->pstn;

//$this->name =  new Add();

//return $this->name;

        }

        public function __set($property_name,$value) 

        { 

            //echo "自动调用__set()方法设置属性值
"; 

            $this->$property_name = $value;

        } 

    } 

    $p1 = new Person;  //这里触发 __construct

    $p1->pstn = "333"; //给内部变量赋值时,触发__set

    //echo $p1->pstn->su();  //获取变量时,触发__get

echo ($p1->pstn);//获取变量时,触发__get

?> 

你可能感兴趣的:(php一些魔术方法简单说明)