Home >Backend Development >PHP Tutorial >PHP global class instance introduction

PHP global class instance introduction

小云云
小云云Original
2018-03-16 11:30:091970browse


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 !";
    }
}

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();

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!

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