Re: late static binding

From: Date: Thu, 31 May 2007 07:06:58 +0000
Subject: Re: late static binding
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-29980@lists.php.net to get a copy of this message
static function getTableName() { return 'PRODS'; } What a great idea! You can just do: $tableName = $this->getTableName(); ...from within the base class. No need for static:: or super:: keywords anymore... It may be not as elegant as having a special keyword for it... (Or if this is the intended solution with PHP)... But, for now, this approach would partially make my code a bit more elegant... Thanx! Now, all I would still like to be able to do is: $className::getTableName(); Jochem Maas wrote:
Richard Lynch wrote:
Maybe I'm just confused (well, I'm always confused...) but if a Class has multiple children, how the heck would PHP know which child:: to call?...
the use of the name 'child' is very confusing, I would prefer 'super' or 'static' ... regardless the concept is actually quite simple: interface DOInfo { static function getTableName(); } abstract class DataObject implements DOInfo { static function findRange() { $table = super::getTableName(); return $foo; // $foo is a collection of whatever (e.g. Product objects) } static function getTableName() { throw new Exception('be a dear and implement '.__METHOD__.' in your subclass'); } } class Product extends DataObject { static function getTableName() { return 'PRODS'; } } $products = Product::findRange(); excuse me if I've just committed a grave sin against the OO Codex in writing something that either isn't 'correct' or is syntactically incorrect according to the current state of php - hopefully the idea is clear anyway.
- Ken -- It looked like something resembling white marble, which was probably what it was: something resembling white marble.
                -- Douglas Adams, "The Hitchhikers Guide to the
Galaxy"


« previous php.internals (#29980) next »