ライン:return 'Static hello ' . self::static_user . '...<br />';
プロデュース: Fatal error: Undefined class constant 'static_user' in ....
注:ロジックはばかげているかもしれませんが、私は今それを使って遊んでいます。質問は、子クラスの抽象クラスの静的変数にアクセスするにはどうすればよいですか?子どものクラスで公開されているもの$public_user
にアクセスできます。$this->public_user
abstract class UserAbstract
{
protected $public_user = null;
static protected $static_user = null;
public function __construct($name)
{
$this->public_user = $name;
self::$static_user = $name;
}
abstract static function static_hello();
}
class User extends UserAbstract
{
static function static_hello()
{
return 'Static hello ' . self::static_user . '...<br />';
}
}
$obj_user = new User('Voodoo');
echo $obj_user->static_hello();