Error message: The $this reference has no context
Reason: In PHP5, $this cannot be used in static methods of static declarations; you need to use self to refer to methods or variables in the current class.Example code is as follows:
Reason: In PHP5, $this cannot be used in static methods of static declarations; you need to use self to refer to methods or variables in the current class.Example code is as follows:
<?php
namespace syhl\admin\page\record; // namespace
require_once dirname(__FILE__).'/../../../../common/smarty_loader.php';
class record {
public static function exec($smarty) {
$ttr=self::getres();
$smarty->assign("arr",$ttr);
$smarty->display ( 'rec_mgr.html' );
}
function getres(){
$arr = array (
"1" => 'test',
'2' => 'me',
array (
"3" => "beij",
"4" => "zz"
),
array (
"5",
"6" => "ewrwer",
"7" => "ssss"
)
);
return $arr;
}
}
record::exec($smarty);
?>
$this(getRes () method in the sample code) is not allowed in the referenced method.
Read More:
- PHP Error Object of class mysqli could not be converted to string in
- php_network_getaddresses: getaddrinfo failed (How to Fix)
- PHP: How to get the total number of data in the MySQL table (total number of rows)
- PHP use __Sleep() and __wakeup() method serializes the object
- [Solved] PHP Fatal error: Uncaught Error: Class ‘Redis‘ not found in
- PHP php-config is not installed error in ubuntu 16 [How to Solve]
- Syntax error: typeerror: about installing sass in vue3 this.getOptions is not a function
- [PHP] Array to string conversion error when sending data in post
- PHP: How to parse MHT file into HTML
- Undefined index: name error in composer [How to Solve]
- How to solve Magento 500 internal server errors
- [Solved] Type error: Argument 1 passed to Monolog\Utils::getClass() must be an instance of Monolog\object
- [PHP]json_encode Chinese JSON_UNESCAPED_UNICODE returns null in php5.3
- How to Hide index.php
- How to Solve PHP Fatal error: Namespace declaration statement has to be the very first statement
- Fatal error: Function name must be a string in
- PHP error in Windows: class’ mysqli ‘not found
- Lack of files in composer installation [How to Solve]
- [Solved] tp6.0 open_basedir Error: Warning: require(): open_basedir restriction in effect.
- How to Solve opcache error: zend_mm_heap corrupted