时间:2021-07-01 10:21:17 帮助过:16人阅读
class Printer { //代理对象,一台打印机
public function printSth() {
echo 'I can print
';
}
// some more function below
// ...
}
class TextShop { //这是一个文印处理店,只文印,卖纸,不照相
private $printer;
public function __construct(Printer $printer) {
$this->printer = $printer;
}
public function sellPaper() { //卖纸
echo 'give you some paper
';
}
public function __call($method, $args) { //将代理对象有的功能交给代理对象处理
if(method_exists($this->printer, $method)) {
$this->printer->$method($args);
}
}
}
class PhotoShop { //这是一个照相店,只文印,拍照,不卖纸
private $printer;
public function __construct(Printer $printer) {
$this->printer = $printer;
}
public function takePhotos() { //照相
echo 'take photos for you
';
}
public function __call($method, $args) { //将代理对象有的功能交给代理对象处理
if(method_exists($this->printer, $method)) {
$this->printer->$method($args);
}
}
}
$printer = new Printer();
$textShop = new TextShop($printer);
$photoShop = new PhotoShop($printer);
$textShop->printSth();
$photoShop->printSth();
?>
function Person(){
this.name = “Mike”;
this.sayGoodbye = function(){"alert(GoodBye!");};
}
Person.prototype.sayHello = function(){alert(”Hello!”);};
function Student(){}
Student.prototype = new Person();
$file = "temp.txt";
$fp = fopen($file , 'w');
if(flock($fp , LOCK_EX)){
fwrite($fp , "abc\n");
flock($fp , LOCK_UN);
}
fclose($fp);
echo strtotime('2014-9-23 10:30:25');