时间:2021-07-01 10:21:17 帮助过:41人阅读
php访问静态方法的方式:1、使用self,代码为【self::test();】;2、使用类名,代码为【a::test()】;3、使用static,代码为【public function test1(){static::test()}】。
php访问静态方法的方式:
1:使用self,代码如下
- <?php
- class a {
- private static function test() {
- echo 'test';
- }
- public function test1() {
- self::test();
- }
- }
- $ab = new a();
- $ab->test1();//结果 test
2:使用类名,代码如下
- <?php
- class a {
- private static function test() {
- echo 'test';
- }
- public function test1() {
- a::test();
- }
- }
- $ab = new a();
- $ab->test1();//结果 test
3:使用static,代码如下
- <?php
- class a {
- private static function test() {
- echo 'test';
- }
- public function test1() {
- static::test();
- }
- }
- $ab = new a();
- $ab->test1();//结果 test
相关学习推荐:php编程(视频)
以上就是php访问静态方法有哪些方式的详细内容,更多请关注gxlcms其它相关文章!