How to determine if php is a static method

PHPz
Release: 2023-03-05 22:16:01
Original
3410 people have browsed it

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();
Copy after login

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();
Copy after login

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();
Copy after login

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());
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!