2

PHP 5.3.3 では、以下のコードは次のエラーで失敗します。

アクティブなクラス スコープがない場合、static:: にアクセスできません

これは、匿名関数が独自のスコープを作成し、クラスのスコープ内にないためであると理解しています。では、PHP 5.5.0 で機能する理由は何でしょうか? PHP 5.4 でも動作しますか? PHP 5.3が明示的に呼び出さないための解決策は何ですかPathController::do_something()

<?php

class PathController
{
    public function get_route()
    {
        return Response::json(Cache::remember('route_point', 10, function() {
            $type_count = array();
            foreach (array("Sprint", "Score", "Section") as $type) {
                $type_count[$type] = static::do_something($type);
            }

            return $type_count;
        }
    }

    //...
}
4

1 に答える 1