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