クラスを作成しようとしていますが、2 つのエラーが発生します。
class Foo {
protected $count;
function __construct() {
$this->count = sizeof($_POST['some_key']);
}
static function get_count() {
echo $this->count; // Problem Line
}
}
$bar = new Foo;
$bar->get_count(); // Problem Call
問題の呼び出しは最後の行にあります。「// Problem Line」コメントのある行で $this を使用すると、「Using $this when not in object context」エラーが生成されます。「this->count」の代わりに「self::count」を使用すると、「未定義のクラス定数エラー」が発生します。私は何が間違っているのでしょうか?