拡張クラスにコピーされない静的変数の回避策を見つけようとしています (これは遅い静的バインディングではうまく機能しません)。書き込みコンテキストで関数の戻り値を使用します" :
<?php
class Person
{
protected static $tlsb_names = ['name'];
protected static $tlsb_vars = [];
public static function & __callStatic($method,$args)
{
echo "call static " . $method . " on " . get_called_class() . "\n";
if(in_array($method,static::$tlsb_names))
{
if(!array_key_exists(get_called_class(),static::$tlsb_vars))
{
static::$tlsb_vars[get_called_class()] = [];
}
if(!array_key_exists($method, static::$tlsb_vars[get_called_class()]))
{
echo "set var $method for " . get_called_class() . "\n";
static::$tlsb_vars[get_called_class()] = null;
}
return static::$tlsb_vars[get_called_class()][$method];
}
}
public static function show_name()
{
static::name() . "\n";
}
public static function call_me_al()
{
static::name() = "Al";
}
public static function call_me_joe()
{
static::name() = "Joe";
}
}
class Al extends Person{}
class Joe extends Person{}
Al::call_me_al();
Joe::call_me_joe();
Al::show_name();
Joe::show_name();
問題のある部分は次の行にあります。
public static function call_me_al()
{
static::name() = "Al";
}
私のエコーが実行されていないため、これは明らかにコンパイル時エラーです。
ここで何が間違っていますか?