php中以类名::方法调用非静态方法

php中静态公开方法static public可以在类外 类名::方法 调用

当没有static的public方法时,在某种条件下也可以采用此方式调用,虽然会报Strict Standards错误

这种条件是调用的这个方法中不能使用代表对象本身的$this

View Code
 1 <?php
 2 //error_reporting(0);
 3 class test {
 4     function tt() {
 5         echo 'tt';
 6     }
 7 
 8     function xx() {
 9         test::tt();
10         echo 'xx';
11     }
12 
13     function ss() {
14         $this->tt();
15         echo 'ss';
16     }
17 }
18 
19 $m = new test;
20 $m::ss(); //致命错误 Fatal error: Using $this when not in object context in XXX
21 test::xx(); //Strict Standards: Non-static method test::ss() should not be called statically in XXX
22 ?>

 

转载于:https://www.cnblogs.com/caps/archive/2013/02/28/2937055.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值