Php, foot, mouth
I found an interesting Php behaviour tonight. The language allows you to call a member function as if it were a static function, something you can accidentally hide when calling callback functions:
// Oops, this calls a non-static member statically as sm::blocks
preg_replace_callback(
"/(?<=\n\n|\r\n\r\n|\r\r|\A)(.*?)(?:\n\n|\r\n\r\n|\r\r|\Z)/sm",
array("sm", "blocks"),
$text);
}
What I really meant was:
array($this, "blocks")
When you call a static function in a Php class, it has the side-effect of wiping out the class context. Without the class context, you can’t make other calls to class members. In my case above, Php allowed me to break the class context (calling a non-static as static) without warning, which caused a perfectly legitimate class member function fail:
function text($m) {
$this->inlines($m);
}
Which fails with: Using $this when not in object context.
Instead, Php should warn: Calling a non-static member as static. This might not be what you meant to do.
