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