PHP类中一般方法与静态方法的疑问
<?php /* 产品类 */ class Product{ public static $Count=0; public $Name=''; public function Show(){ print('<p>Show Method</p>'); } public static function Display(){ print('<p>Display Static Method</>'); } } $class = new ReflectionClass('Product'); print "<pre>"; Reflection::export($class); print "</pre>"; Product::Display(); Product::Show();//为什么非静态方法在这里也可以用::的方式访问? ?>
Class [ class Product ] {
@@ D:\WebRoot\static.php 5-16
- Constants [0] {
}
- Static properties [1] {
Property [ public static $Count ]
}
- Static methods [1] {
Method [ static public method Display ] {
@@ D:\WebRoot\static.php 13 - 15
}
}
- Properties [1] {
Property [ public $Name ]
}
- Methods [1] {
Method [ public method Show ] {
@@ D:\WebRoot\static.php 9 - 11
}
}
}
Display Static Method
Show Method
以上是程序执行的结果,Show方法明明是一个一般方法,为什么也可以用Product::Show()访问,程序并不会出错,这样访问和静态方法的访问不是一样吗?要是真是这样,那还要静态方法干吗?请哪位有明白的指点一二。谢谢!!!
申明
非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!
博文欢迎转载,但请给出原文连接。