调用静态方法而已<?php class Foo { public static function aStaticMethod() { // ... } }Foo::aStaticMethod(); ?> 两种写法都可以
我的function没写static也能Class::Function()这样调用
如果是model类就创建实例 是function类就直接调用 是不是可以这样理解
[Editor's Note: This is done for back compatability. Depending on your error level, An E_STRICT error will be thrown.]PHP 5.0.1 doesn't seem to mind if you call a static method in a non-static context, though it might not be the best of style to do so.On the other hand, PHP complains if you try to try to call a non-static method in a static context (if your error reporting is cranked up to E_STRICT).class Test {
static function static_method() { echo "Here's your static method: Foo!<br />\n"; } function static_method_caller() { echo "static_method_caller says: ";$this->static_method(); } function non_static() { echo "I am not a static method<br />\n"; }}$t = new Test(); $t->static_method(); $t->static_method_caller(); Test::non_static(); 见手册
class Foo {
public static function aStaticMethod() {
// ...
}
}Foo::aStaticMethod();
?>
两种写法都可以
是不是可以这样理解
[Editor's Note: This is done for back compatability. Depending on your error level, An E_STRICT error will be thrown.]PHP 5.0.1 doesn't seem to mind if you call a static method in a non-static context, though it might not be the best of style to do so.On the other hand, PHP complains if you try to try to call a non-static method in a static context (if your error reporting is cranked up to E_STRICT).class Test {
static function static_method() {
echo "Here's your static method: Foo!<br />\n";
}
function static_method_caller() {
echo "static_method_caller says: ";$this->static_method();
}
function non_static() {
echo "I am not a static method<br />\n";
}}$t = new Test();
$t->static_method();
$t->static_method_caller();
Test::non_static();
见手册
被静态调用的类方法中不得出现 $this,可理解为该方法仅仅是打包一个函数