What you are using is obviously very irregular. Of course, let’s get to the point first. To adjust the non-static method of the parent class, first you have to get the class instance If there is a cache, just get it directly, if not, create one
$instance = new self();
$totalCount = $instance->get_one_bysql($sqlstr);
<?php
class a{
public $ab = NULL;
public function d(){
var_dump($this->ab);
}
public function c($a,$b){
var_dump($a+$b);
}
}
class b extends a{
public static function t(){
// $this->d(); //Fatal error: Using $this when not in object context in D:\phpStudy\WWW\index.php on line 14
// $this->c(1,2); //Fatal error: Using $this when not in object context in D:\phpStudy\WWW\index.php on line 15
// self::d(); //Strict Standards: Non-static method a::d() should not be called statically in D:\phpStudy\WWW\index.php on line 16
//Fatal error: Using $this when not in object context in D:\phpStudy\WWW\index.php on line 5
// self::c(1,2); //Strict Standards: Non-static method a::c() should not be called statically in D:\phpStudy\WWW\index.php on line 18
// int(3)
// parent::d(); //Strict Standards: Non-static method a::d() should not be called statically in D:\phpStudy\WWW\index.php on line 20
// Fatal error: Using $this when not in object context in D:\phpStudy\WWW\index.php on line 5
// parent::c(1,2); //Strict Standards: Non-static method a::c() should not be called statically in D:\phpStudy\WWW\index.php on line 22
//int(3)
}
}
b::t();
Summary: this is used for instance calls. self, parent are used to call static properties or methods. The last strange phenomenon is that although statically calling the non-static method of the parent class to process data will get an error, int(3) is still output
self::get_one_by_sql
First make sure the get_one_bysql of the parent class is static
About using https://stackoverflow.com/que...
What you are using is obviously very irregular. Of course, let’s get to the point first.
To adjust the non-static method of the parent class, first you have to get the class instance
If there is a cache, just get it directly, if not, create one
Cannot be called.
Non-static methods need to have the $this object, and this object cannot be provided when calling from static methods.
Open the comments and play around to find out
Summary: this is used for instance calls. self, parent are used to call static properties or methods.
The last strange phenomenon is that although statically calling the non-static method of the parent class to process data will get an error, int(3) is still output