Home >Backend Development >PHP Tutorial >PHP, how to call member functions of a class from a function outside a class

PHP, how to call member functions of a class from a function outside a class

巴扎黑
巴扎黑Original
2016-11-30 09:45:571758browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn