登录

请教PHP不同环境出现Non-static method 错误问题

php5.2.17下代码运行正常,

php5.4以上就报错。

源码如下:

入口Gateway.php文档:

<?php require dirname(__FILE__) . '/Command.php';

$d=$_POST['data'];

if(get_magic_quotes_gpc()){

$d=stripslashes($d);

}

$param = json_decode($d);

$ret = Command::call($param);


header('content-type:application:json;charset=utf8');

header('Access-Control-Allow-Origin:*');

header('Access-Control-Allow-Methods:POST');

header('Access-Control-Allow-Headers:x-requested-with,content-type');

echo json_encode($ret);

?>


Commadn.php文档:

<?php

require dirname(__FILE__) . '/service.inc.php';

class Command{

    pulibic function call($params){

        $result = self::callMethod(*********);

        return $result;

    }

private function callMethod(***){

try {

     if(count($params)>0){

     $result=call_user_func_array(Array($classStr,$funcStr),$params);

     }else{

     $result=call_user_func(Array($classStr,$funcStr));

     }       

     $ret[] = 1;

     $ret[] = $result;   

     }catch (Exception $e){

        ****************

    }

    return $result;

}

service.inc.php文档

<?php

define("WG_SERVER_BASE",dirname(__FILE__) . "/");


if (isset($GLOBALS['includefiles'.__FILE__])){

    return;

}else{

     $GLOBALS['includefiles'.__FILE__]=true;

     function __autoload($class_name) {

     //判断文件是否存在

     if(strpos($class_name,"Service")!==false){

         $fileUrl = WG_SERVER_BASE. 'service/'.$class_name.'.php';

         }else if(strpos($class_name,"API")!==false){

         $fileUrl = WG_SERVER_BASE. 'api/'.PLATFORM_TYPE."/".$class_name.'.php';

         }else if(strpos($class_name,"Data")!==false){

         $fileUrl = WG_SERVER_BASE. 'data/'.$class_name.'.php';

     }else{

          $fileUrl = WG_SERVER_BASE.$class_name.'.php';

     }

     if(file_exists($fileUrl)){

       require $fileUrl;

     }

}

date_default_timezone_set('Etc/GMT-8'); 

}

PH环境5.4以上报错,5.2却正常,求教如何兼容PHP5.2--5.6环境而不出错???,错误代码:

Strict standards: Non-static method Command::call() should not be called statically in ***/Gateway.php on line 13


Strict standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method ******** should not be called statically in ***********


Warning: Cannot modify header information - headers already sent by (output started at **********Command.php:62) in *************\Gateway.php on line 16

# PHP
虎威虎威1588 天前3367 次浏览

全部回复(2) 我要回复

  • 虎威

    虎威2018-03-27 11:36:28

    问题补充:如果无法兼容5.2--5.6,那请教如何将上面的可以在5.2环境下正常运行的代码改造成5.4以上可执行?

    回复
    0
  • 好人二狗

    $obj = new Command; $obj->call(); 这样调用试试

    好人二狗 · 2018-03-29 12:24:01
  • 取消回复发送