PHP global class instance introduction

小云云
Release: 2023-03-21 15:16:01
Original
1941 people have browsed it


This article mainly shares with you an introduction to php global class examples, hoping to help everyone.

Just like the hello class below

<?phpclass hello{
    function say()
    {
        echo "hello world !";
    }
}
Copy after login

It is also very easy to call the global class. Like this, it can be easily called

<?phprequire_once(&#39;test1.php&#39;);
require_once(&#39;test2.php&#39;);
require_once(&#39;hello.php&#39;);
use space\test1\test;use space\test2\test as test2;$test1 = new test();$test2 = new test2();
$hello = new \hello();$test1->say();
$test2->say();
$hello->say();
Copy after login

In the new keyword before instantiating the class in the class Add \ before the name to instantiate the global class

The above is the detailed content of PHP global class instance introduction. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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