0
由於PHP 5.3中的繼承問題,導致static關鍵字出現問題。PHP 5.3中的後期靜態在繼承時不會產生預期結果
abstract class Object
{
protected static $_classDataSource = null;
public static function getDataSource()
{
return static::$_classDataSource;
}
public static function setDataSource($dataSource)
{
static::$_classDataSource = $dataSource;
}
}
class Film extends Object
{
}
class Actor extends Object
{
}
Film::setDataSource('FFF');
Actor::setDataSource('aaa');
echo Film::getDataSource();
echo Actor::getDataSource();
結果是: AAAAAA 預期的結果: FFFaaa
我應該怎麼做,使之如預期?
[PHP5&Abstract Classes。單獨的每個子類的類變量副本?](http://stackoverflow.com/questions/3391788/php5-abstract-classes-separate-copy-of-class-variables-for-each-child-class) – Artefacto 2010-08-09 17:58:00
請參閱也http://stackoverflow.com/questions/3187124/peculiar-behaviour-with-php-5-3-static-inheritance-and-references – Artefacto 2010-08-09 18:00:36