The question is in t开发者_高级运维he title.
They are non-static by default:
public function method() {
}
You will get an E_STRICT
if you call it statically, but I don't think you can easily enforce that it can only be called on an instance - if you try to check You could do $this
I think you will get an error.isset($this)
as Artefacto says and throw an exception if it isn't set.
<?php
class abc() {
public function foo() {
...
}
}
$c = new abc();
$c->foo();
?>
<?php
class abc() {
public function foo() {
if (!isset($this)) {
throw new Exception('Method is non-static.');
exit();
}
}
}
$c = new abc();
$c->foo();
?>
Not tested.
精彩评论