Please tell me about the Non-static method error in different PHP environments.
虎威
虎威 2018-03-27 11:27:47
0
2
4210
The code runs normally under

php5.2.17, but an error occurs when

php5.4 or above.

The source code is as follows:

Entrance Gateway.php document:

<?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 document:

<?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; ***

}

return $result;

}

service.inc.php document

<?php

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

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

return;

}else{


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

function __autoload($class_name) {

//Determine whether the file exists

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

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

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

                                                                                . '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. '.'. ){

require $fileUrl;

}

}

date_default_timezone_set('Etc/GMT-8');

}

In PH environment 5.4 and above, an error is reported, but in 5.2 it is normal. How can I make it compatible with PHP5.2--5.6 environment without errors? ? ? , Error code:

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

虎威
虎威

reply all(1)
虎威

Additional question: If it is not compatible with 5.2--5.6, then please tell me how to transform the above code that can run normally in the 5.2 environment to be executable in 5.4 or above?

  • reply $obj = new Command; $obj-&gt;call(); Try calling it like this
    好人二狗 author 2018-03-29 12:24:01
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template