例として、次のコードを取り上げます。
class xpto
{
public function __get($key)
{
return $key;
}
}
function xpto()
{
static $instance = null;
if (is_null($instance) === true)
{
$instance = new xpto();
}
return $instance;
}
echo xpto()->haha; // returns "haha"
今、同じ結果をアーカイブしようとしていますが、xpto クラスを記述する必要はありません。私の推測では、次のように書く必要があります。
function xpto()
{
static $instance = null;
if (is_null($instance) === true)
{
$instance = new stdClass();
}
return $instance;
}
echo xpto()->haha; // doesn't work - obviously
さて、__get() マジック機能を stdClass オブジェクトに追加することは可能ですか? ないと思いますが、よくわかりません。