【发布时间】:2013-08-16 06:20:50
【问题描述】:
我认为通常我们使用静态方法是因为我们不需要实例化对象。并且我们可以使用className::staticFunction来调用静态方法,bub今天发现:
test1.php
<?php
class Foo {
static public function helloWorld() {
print "Hello world " ;
}
}
Foo::helloWorld();
test2.php
<?php
class Foo {
public function helloWorld() {
print "Hello world " ;
}
}
Foo::helloWorld();
问题:
以上两个脚本都有效。我们没有将函数声明为static,我们仍然可以使用className::staticFunction 来调用函数。为什么我们需要使用静态方法?
【问题讨论】:
-
希望这能解决您的问题stackoverflow.com/questions/1257371/…
标签: php