Php 在类中调用多级函数
我看到一些免费类库做了一些非常有趣的事情,比如 wideimage,phpExceldo,它的调用如下 $class=新的WideImage //宽图像 $class->load()->resize()->addnoise()->saveToFile() 我想学习它,但我不知道,我想它使用函数_call(){}但我试过了,但它不起作用,有人能教我怎么做吗?我试着搜索stackoverflow和google,但我不知道我应该搜索什么关键字LOLPhp 在类中调用多级函数,php,function,class,Php,Function,Class,我看到一些免费类库做了一些非常有趣的事情,比如 wideimage,phpExceldo,它的调用如下 $class=新的WideImage //宽图像 $class->load()->resize()->addnoise()->saveToFile() 我想学习它,但我不知道,我想它使用函数_call(){}但我试过了,但它不起作用,有人能教我怎么做吗?我试着搜索stackoverflow和google,但我不知道我应该搜索什么关键字LOL <?php namespace system
<?php
namespace system\classes {
if(!defined('IN_APP')){
exit('ACCESS DENIED.');
}
class images
{
protected $_root;
protected $_attachment;
protected $_image_path;
protected $image;
public $image_container;
public function __construct(){
global $_G;
$this->_root = getglobal('attachment/path/root');
$this->_attachment = getglobal('attachment/path/sub');
$this->_image_path = $this->_root . DS . $this->_attachment . DS . getglobal('attachment/path/images') . DS;
if(!$this->image || $this->image == '' || null($this->image)){
$this->image = new \system\classes\wideimage\WideImage();
}
}
public function load($var){
$matrix = array(array(2,0,0),array(0, -1, 0), array(0, 0, -1));
// $this->image = $this->image->loadFromUpload($var)->crop(50,50)->resize(100,100)->rotate(200,200)->addNoise(300, 'mono')->applyConvolution($matrix, 1, 220);
$this->image = $this->image->loadFromUpload($var);
// exit(var_dump($this->_image_path));
}
public function resize($width, $height){
$this->image = $this->image->resize($width, $height);
}
public function save(){
// exit(var_dump($this->image_container));
$this->image = $this->image->saveToFile('name.gif');
}
public function __call($name,$arg){
exit(var_dump($name));
}
}
}
?>
我尝试了$images->load('img')->save()
php给了我一个错误
致命错误:对中的非对象调用成员函数save()
->
操作符调用对象上的方法。因此,您必须从函数返回一个对象,这样您就可以调用方法了。最简单的方法是只返回$this
,这样您就又有了用于初始方法调用的相同对象实例
这个关键词很简单,但我不知道该搜索什么……谢谢
if(isset($_FILES['img'])){
$images = new system\classes\images();
$images->load('img')->save();
// $images->save();
}