.
January 4th, 2007 - Grin with cat attached — LiveJournal

January 4th, 2007

OOP coding query

PHP, with a flamboyant disregard for static/dynamic separation, allows me to do the following:

class thingy{
static function boo() { print('BOO'); }

function bang() { print('BANG'); }
}

$myThing=new thingy();
thingy::bang();
$myThing->boo();

ie, it makes no effort to stop me calling static functions (or members) in a dynamic (and probably misleading) fashion. I'd expect $myThing->boo() to throw a (probably fatal) error saying something like "Static method called dynamically". Without this protection, I'd suspect that allocations to a static variable from inside an object would cause changes not merely within the object scope, but within all objects *and* the class scope, which feels like a world-class "gotcha" waiting to happen.


Is this common among OOP languages, or is this just another example of PHP's juvenile status?
6 comments | Leave a comment