Php 将消息传递到前端

Php 将消息传递到前端,php,static-variables,custom-errors,Php,Static Variables,Custom Errors,我正在尝试用PHP之类的语言编写文件,我编写了一个基本类,它没有完全实现,如您所见: class AisisCore_FileHandling_Upload_Upload{ private $_file; static private $_errors; public function __construct() { $this->init(); } public function init(){} public f

我正在尝试用PHP之类的语言编写文件,我编写了一个基本类,它没有完全实现,如您所见:

class AisisCore_FileHandling_Upload_Upload{

    private $_file;

    static private $_errors;

    public function __construct() {
        $this->init();
    }

    public function init(){}

    public function check_file(array $file, string $size){
        $this->_file = $file;

        if ($this->_file['size'] > $size) {
            $this->_error('size', 'The size of your zip exceeds that of the set size: ' . $size);
        }

        if ($this->_file['type'] != 'application/zip') {
            $this->_error('type', 'File type must be a .zip');
        }

        if (!strops($this->_file['name'], 'package') || !strops($this->_file['name'] == 'theme')) {
            $this->_error('name', 'File uploaded does not contain the words "package" or "theme." Unreconized.');
        }elseif(strops($this->_file['name'], 'package')){
            $this->package($this->_file);
        }elseif(strops($this->_file['name'], 'theme')){
            $this->theme($this->_file);
        }   

        wp_safe_redirect(admin_url('admin.php?page=aisis-core-upload'));
    }

    public function theme(array $file){ 
    }

    public function package(array $file){
    }

    protected function _error(string $code, string $message){
        self::$_errors[$code] = $message;
    }

    public function get_all_errors(){
        foreach($this->_errors as $code=>$message){
            echo '<div class="alert alert-error"><strong>'.$code.'</strong>: '.$message.'</div>';
        }
    }
}
class AisisCore\u文件处理\u上传\u上传{
私有$u文件;
静态私有$u错误;
公共函数构造(){
$this->init();
}
公共函数init(){}
公共函数检查_文件(数组$file,字符串$size){
$this->_file=$file;
如果($this->_文件['size']>$size){
$this->_错误('size','zip的大小超过了设置的大小:'。$size);
}
如果($this->_文件['type']!='application/zip'){
$this->_错误('type','File type必须是.zip');
}
如果(!strops($this->_文件['name'],'package')| |!strops($this->_文件['name']=='theme')){
$this->_错误('name','File uploaded不包含单词“package”或“theme.”未恢复。');
}elseif(strops($this->_文件['name'],'package')){
$this->package($this->\u文件);
}elseif(strops($this->_文件['name'],'theme')){
$this->theme($this->\u文件);
}   
wp_safe_重定向(admin_url('admin.php?page=aisiscore upload');
}
公共函数主题(数组$file){
}
公共函数包(数组$file){
}
受保护函数\u错误(字符串$code,字符串$message){
self::$\u错误[$code]=$message;
}
公共函数get_all_errors(){
foreach($this->\u错误为$code=>$message){
回显“”.$code.”:“.$message.”;
}
}
}
此类与窗体交互:

$upload = new AisisCore_FileHandling_Upload_Upload();

if($_POST['aisis_upload']){
    $upload->check_file($_FILES['aisis_file'], $_POST['MAX']);
}

$upload->get_all_errors();

<form action="" method="POST">
    <fieldset>
        <div class="control-group">
            <input type="file" class="input-xlarge" name="aisis_file" placeholder="Your file.">
            <input type="hidden" name="MAX" value="1024">
        </div>
        <div class="control-group">
            <input type="submit" class="btn btn-primary" value="Upload Zip" name="aisis_upload">
        </div>
    </fieldset> 
</form>
$upload=new AisisCore\u FileHandling\u upload\u upload();
如果($_POST['aisis_upload'])){
$upload->check_文件($_文件['aisis_文件],$_POST['MAX']);
}
$upload->获取所有错误();
当表单与违反“检查”规则的文件一起提交时,它应该(正如您从
wp\u safe\u重定向(admin\u url('admin.php?page=aisis core upload'));
)重定向回它所在的页面(无论文件通过还是失败,在说了什么都做了什么的情况下,这种重定向也会发生)

我遇到的问题是,我将错误存储在一个静态变量中,当我返回页面时,应该保存该变量,从那里我应该能够将错误取出, 相反,我得到的是什么都没有。只是一个空白页,没有错误吐出来,xdebug是沉默的

我该如何调试它呢?我在提交之前和之后尝试了var转储错误,但是在它为null之前,就像它应该是一样,在提交之后,页面是空白的


想法?

调试最简单的方法是注释掉重定向,但如果需要,也可以使用session变量将信息传送到下一页。也就是说,如果要查找错误,请查看strop(及其strop而非strops)的用法

在第一个条件中,您应该检查!==false(字符串包含针)或===false(字符串不包含针)。如果名称为“package”,则strpos将返回0,该值==false,这可能不是您想要的。第二个条件是,strpos似乎不必要,或者至少使用了错误。对于strpos的false值,请按如下方式执行

if(strpos($this->_file['name'] , 'theme' ) === false) 
更多信息

if(strpos($this->_file['name'] , 'theme' ) === false)