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

巴扎黑
Release: 2023-03-01 10:40:01
Original
1756 people have browsed it

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.

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template