Hi,
I am not sure it's the right place to discuss this. someday I found I call a static method instancely.
the method is just a helper method when reviewing my code. I know I do the wrong thing, but PHP doesn't
complain about it. then I do some tests like below:
<?php
error_reporting(E_ALL ^ E_STRICT);
class A {
public function static staticFunc() {
echo "static";
}
public function instanceFunc() {
echo "instace";
}
}
A::instanceFunct(); // Strict Standards: Non-static method A::instanceFunc() ...
$a = new A();
$a->staticFunc(); // Just static no E_STRICT
error raised
I know it's the wrong way to do like these, maybe there are some historical reasons to allow these.
I just wonder why previous method call raise E_STRICT
but later not.
Yes, something could be done doesn't means we should, but we could stop things like happened.
reeze wrote:
Hi,
I am not sure it's the right place to discuss this. someday I found I call a static method instancely.
the method is just a helper method when reviewing my code. I know I do the wrong thing, but PHP doesn't
complain about it. then I do some tests like below:
A few corrections to your test case so it actually works.
<?php
error_reporting(E_ALL ^ E_STRICT);
I think you wantE_ALL
|E_STRICT
class A {
public function static staticFunc() {
This is a parse error. static should be placed before function.
echo "static";
}
public function instanceFunc() {
echo "instace";
}
}A::instanceFunct(); // Strict Standards: Non-static method A::instanceFunc() ...
And this should be A::instanceFunc();
$a = new A();
$a->staticFunc(); // Just static noE_STRICT
error raisedI know it's the wrong way to do like these, maybe there are some historical reasons to allow these.
I just wonder why previous method call raiseE_STRICT
but later not.Yes, something could be done doesn't means we should, but we could stop things like happened.
I think it may be related to inheritance.