Do you have any ideas on how to allow this to be at all useful with
inheritance and overriding? If the patch is left to where these examples
would all return 'A' and something wasn't put in place to allow
overloading a static function AND forward on the original called class
What do you mean by "overloading a static function"? What you are trying
to do?
I have explained this on list twice already...but here it goes again, maybe
a slightly more concrete example will help:
Say I have a class that is used to generate queries based on the values of
certain static properties.
<?php
class TableSelectBuilder
{
static protected $tableName;
static protected $tableColumns;
static protected function buildSelectQuery()
{
return "SELECT ".implode(', ', static::$tableColumns)." FROM
".static::$tableName;
}
}
class TestTableSelectBuilder extends TableSelectBuilder
{
static protected $tableName = 'test';
static protected $tableColumns = array('col1', 'col2', 'col3');
static public function test()
{
return self::buildSelectQuery();
}
}
echo TestTableQueryBuilder::test()."\n";
?>
Running this script using the latest patch by Dmitry or Etienne will echo
"SELECT col1, col2, col3 FROM test". This is perfect, I love it. Now I want
to extend TableSelectBuilder to prepend EXPLAIN to a query. I then want to
change TestTableSelectBuilder to extend that class instead
<?php
class TableSelectBuilder
{
static protected $tableName;
static protected $tableColumns;
static protected function buildSelectQuery()
{
return "SELECT ".implode(', ', static::$tableColumns)." FROM
".static::$tableName;
}
}
class TableSelectExplainBuilder extends TableSelectBuilder
{
static protected function buildSelectQuery()
{
return "EXPLAIN ".parent::buildSelectQuery();
}
}
class TestTableQueryBuilder extends TableSelectExplainBuilder
{
static protected $tableName = 'test';
static protected $tableColumns = array('col1', 'col2', 'col3');
static public function test()
{
return self::buildSelectQuery();
}
}
echo TestTableQueryBuilder::test()."\n";
?>
This now echos "EXPLAIN SELECT FROM". This is obviously not what is
desired. Changing parent:: to static:: will cause a segfault due to infinite
recursion as will self::. So in short there is absolutely no way to make
TableSelectExplainBuilder useful in the current patch without duplicating
the parent class code. This limitation is part of the problem that lsb is
supposed to solve.
to the parent class then usefulness of late static binding is php is
going to be diminished.
Usefulness for what?
--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED] http://www.zend.com/
(408)253-8829 MSN: [EMAIL PROTECTED]
--
No virus found in this incoming message.
Checked by AVG Free Edition. Version: 7.5.487 / Virus Database:
269.13.21/1010 - Release Date: 9/15/2007 7:54 PM
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php