suin.io

PHP5でキーワードを関数名にするとエラー

suin2008年5月18日

PHP5(5.2.4で確認)では、つぎの様なキーワードを関数名とするメンバ関数を作るとエラーになります。Troubleshooting PHP5 Problems


	protected function catch()
	{}

catchの他にも、abstract・clone・final・implements・interface・private・protected・public・throw・tryなどをメソッド名にするとエラーが起こるらしいです。

Parse error: syntax error, unexpected T_ABSTRACT, expecting T_STRING
Parse error: syntax error, unexpected T_CATCH, expecting T_STRING
Parse error: syntax error, unexpected T_CLONE, expecting T_STRING
Parse error: syntax error, unexpected T_FINAL, expecting T_STRING
Parse error: syntax error, unexpected T_IMPLEMENTS, expecting T_STRING
Parse error: syntax error, unexpected T_INTERFACE, expecting T_STRING
Parse error: syntax error, unexpected T_PRIVATE, expecting T_STRING
Parse error: syntax error, unexpected T_PROTECTED, expecting T_STRING
Parse error: syntax error, unexpected T_PUBLIC, expecting T_STRING
Parse error: syntax error, unexpected T_THROW, expecting T_STRING
Parse error: syntax error, unexpected T_TRY, expecting T_STRING

いまのところ解決策はないようなので、PHP4を意図して、abstract・clone・final・implements・interface・private・protected・public・throw・tryなどをメンバ関数にしたスクリプトをPHP5で動かす場合は注意する必要があります。一時的な回避策としてはメソッド名を変える方法があります。

RELATED POSTS