Home > Article > Backend Development > PHP, how to call member functions of a class from a function outside a class
There is a database operation class class mySql_Class, and it has been instantiated. How can a function outside the class call the member function of the class? The premise is that the class is not instantiated again within the function outside the class. I saw someone on the Internet saying to add global $mySql_Class; to the extra-class function; but I tried it but it didn’t work.
Solution:
$c=new mySql_Class;
function x()
{
global $c;
$c->doMethod();
}
It can’t not work, that’s how it is used.
Of course you cannot call its private methods.