|
Posted by Michael Fesser on 01/09/08 09:18
..oO(Peter Pei)
>The following code works, and that bothers me. Actually two things bothered
>me:
>1) Essentially PHP is not very strict about static and non-static. function
>say() is not declared as static, but it was written as if it is static: the
>use of self:: and accessing a static value, and it can actually be accessed
>as a static function (meaning not from an instance);
With error_reporting = E_ALL|E_STRICT you'll get a warning:
Strict Standards: Non-static method A::say() should not be called
statically in [...]
>2) As the code showed, function say() can be called from both the class (as
>if it is static) or from one of its instance (as if it is not static).
>
>Interesting...
>
><?php
> class A {
> public static $a = 12;
> public function say() {
> print self::$a . "\n";
> }
> }
>
> A::say();
> //the following does not work
> $a = new A();
> $a->say();
>?>
Both work here, except for the E_STRICT warning.
Micha
Navigation:
[Reply to this message]
|