Home  >  Article  >  Backend Development  >  How to determine if php is a static method

How to determine if php is a static method

PHPz
PHPzOriginal
2020-09-25 15:10:213496browse

php method to determine whether it is a static method: 1. Use the access form of the static method to access the ordinary method, the code is [$class =new Test();$class::wz]; 2. Use the ordinary method To access static methods, the code is [$class = new Test();].

How to determine if php is a static method

[Related learning recommendations: php graphic tutorial

php method to determine whether it is a static method:

1. Create a new file, create a class, and write a static method, an ordinary method :

<?php
class Test
{
    public function wzl(){
        echo &#39;我是一个普通方法<br>&#39;;
  
    }
  
    public static function cwh(){
        echo &#39;我是一个静态方法<br>&#39;;
  
    }
  
}
$class = new Test();
$class->wzl();
$class::cwh();

2. Use the browser to access the file and view the results:

How to determine if php is a static method

3. If we use the static method access form to access the ordinary method

$class = new Test();
$class::wzl();

The result is as follows:

How to determine if php is a static method

##4. If we use the access form of ordinary method to access the static method

$class = new Test();
$class->cwh();

The result is as follows:

How to determine if php is a static method

5. In addition, it can also be judged through mapping. Edit as follows:

$rm = new ReflectionMethod(&#39;Test&#39;,&#39;wzl&#39;);
  
var_dump($rm->isStatic());
  
$rm2 = new ReflectionMethod(&#39;Test&#39;,&#39;cwh&#39;);
  
var_dump($rm2->isStatic());

How to determine if php is a static method

Related learning recommendations:

php Programming(Video)

The above is the detailed content of How to determine if php is a static method. 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