<?php //flag is in flag.php error_reporting(1); class Read { public $var; /*Read类的一个函数*/ public function file_get($value) { $text = base64_encode(file_get_contents($value)); #将文件的内容以字符串的形式读取出来,并进行base64的加密 return $text; } /*当以函数的方法调用一个Read类实例时,会先调用__invoke方法*/ public function __invoke(){ $content = $this->file_get($this->var); #将被base64加密的文件的内容赋值给$comtent echo $content; } }
class Show{ public $source; public $str; /*当初始化一个Show实例的时候,默认他的file属性为index.php*/ public function __consturct($file='index.php'){ $this->source = $file; #将index.php赋值给$this->source echo $this->source."Welcome"."<br>"; #显示index.php Welcomee } /*当一个Show的类实例被当作一个字符串使用时,会。。。。*/ public function __toString(){ return $this->str['str']->source;//注意这里,很奇怪。调用了一个从来没有的类属性, //所以会调用get方法。而同时正常到$this->str['str']就返回了键值了,但是它后面又有一个取属性的操作。 //所以想$this->str['str']本身就是一个有source属性的一个类的实例 } /*这应该不是一个内置的魔术方法,,,*/ public function _show(){ if(preg_match('/gopher|http|ftp|https|dict|\.\.|flag|file/i',$this->source)){ die('hacker'); } else{ highlight_file($this->source); } } /*当对一个Show实例进行反序列化之前调用*/ public function __wakeup(){ if(preg_match("/gopher|http|file|ftp|https|dict|\.\./i",$this->source)){ echo "hacker"; $this->source="index.php"; } } }
class Test{ public $p; public function __construct(){ $this->p = array(); } /*在获取一个Test的类成员的时候调用:$a->bbb*/ public function __get($key){ $function = $this->p; return $function(); } }
public function __toString(){ return $this->str['str']->source;//注意这里,很奇怪。调用了一个从来没有的类属性, //所以会调用get方法。而同时正常到$this->str['str']就返回了键值了,但是它后面又有一个取属性的操作。 //所以想$this->str['str']本身就是一个有source属性的一个类的实例 }