I am trying to access the global variable in a Static Method, But i am getting the Fatal Error:
Fatal error: Call to a member function prepare() on a non-object
Means my static variable can't hold the global variable, but this standard works with the normal method( without static ).
class Payment_Handler {
private static $dbh;
function __construct() {
global $dbh;
self::$dbh = $dbh;
}
/**
* Verify Secret Key
*
* @param string $secret_key
* @return boolean
*/
static function verify_secret( $secret_key ) {
// Do the stuff with self::$dbh
$query = "............";
$stmt = self::$dbh->prepare($query);
}
} // End Class
I also tried over google but no luck. Please tell me what mistake i have done, and why it is not accessible by static variable?
$obj->verify_secret()so that during object instantiation property is set via__construct