class Foo {
public static function bar() {
echo "foo\n";
}
}
class Zap extends Foo {
public static function bar() {
parent::bar();
}
}
$z = new Zap();
$z->bar();
In PHP, the parent:: token is ambiguous. It works equally well in static and object calling contexts. Basically, it passes along the calling context to the next function up. If you had declared bar() previously as non-static, you wouldn't notice any errors in this setting. But the behavior of calling Zap::bar() would change drastically.
The point is, if you're changing a method from non-static to static, you need to be aware of the internals of all the functions which subclass it. If they call parent::bar(), the result could be unexpected. In the above example, $z would not be modified at all, and no errors, warnings, nor E_STRICTS would be thrown.
No comments:
Post a Comment