|
Posted by Peter Pei on 01/09/08 04:02
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);
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();
?>
Navigation:
[Reply to this message]
|