プライベート ディスパッチ テーブルを持つクラスがあるとします。
$this->dispatch = array(
1 => $this->someFunction,
2 => $this->anotherFunction
);
私が電話したら
$this->dispatch[1]();
メソッドが文字列ではないというエラーが表示されます。次のような文字列にすると:
$this->dispatch = array(
1 => '$this->someFunction'
);
これにより 致命的なエラーが発生します: Call to undefined function $this->someFunction()
私も使用してみました:
call_user_func(array(SomeClass,$this->dispatch[1]));
メッセージの結果: call_user_func(SomeClass::$this->someFunction) [function.call-user-func]: First argument is expected to be a valid callback .
編集: $this が SomeClass のときに SomeClass::$this を呼び出しているため、これはあまり意味がないことに気付きました。配列を含むいくつかの方法でこれを試しました
array($this, $disptach[1])
これはまだ私が必要とするものを達成していません。
編集を終了
これは、クラスがなく、いくつかの関数を含むディスパッチ ファイルがある場合に機能します。たとえば、これは機能します:
$dispatch = array(
1 => someFunction,
2 => anotherFunction
);
これらをクラスのプライベートメソッドとして保持しながら、ディスパッチテーブルで使用できる方法があるかどうか疑問に思っています。