php魔法函数

<?php
//http://yaoqianglilan.blog.163.com/blog/static/709783162010111344822327/
//http://zhidao.baidu.com/question/505807908.html
header("content-type:text/html;charset=utf-8");
class magicClass{
private $username;
public $age;
static $sex;
function __construct(){
$this->username="test";
$this->age=100;
//$this->sex="男";
self::$sex="男";
}
function getInfo($username){
$sex=self::$sex;
return "用户信息为:".$username.",性别:".$sex;
}
function __get($key){
echo $key."不存在";
}
function __set($key,$value){
echo "对".$key."赋值".$value;
}
function __call($Key, $Args)
{
echo "您要调用的{$Key}方法不存在。你传入的参数是:".print_r($Args,true);
}
function __toString(){
return "打印 Test";
}
public static function test(){
echo "性别为:".self::$sex;
}
}
$magic=new magicClass;
echo $magic;
echo $magic->age;
echo "<br>";
echo $magic->sex;
echo "<br>";
echo $magic->getInfo('victor');
echo "<br>";
$magic->sex="男";
echo "<br>";
$magic->test();
echo "<br>";
/** 
* 重写 __autoload方法 
*/ 
function __autoload($class){ 
include $class.'.php'; 

$test=new Test_autoload(); 
unset($test); 
echo "<br>";
echo method_exists("magicClass","getInfo");
echo $magic->test();
echo "<br>";
//类的名称::方法名称
magicClass::test();

?>

Test_autoload.php

<?php 
/** 
* 测试__autoload方法 

*/ 
class Test_autoload { 
function __construct () { 
echo " Test_autoload. " ; 


?>

    A+
发布日期:2014年07月10日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: