« PHP 8.3 Manual トップ
著作権 »
per page, with , order by , clip by
Results of 1 - 1 of about 1 for testReturnCatch (0.001 sec.)
finally | PHP 8.3 9414
finally (PHP 5 >= 5.5.0, PHP 7, PHP 8) catch ブロックの後、またはその代わりに、 finally ブロックも指定できます。 finally ブロックの中に書いたコードは、 return 文や yield 文に到達した場合や、 Throwable エラーがキャッチされなかったり、 スロー ... try { echo 'Within try' , "\n" ; return 'try' ; } finally { echo 'Within finally' , "\n" ; return 'finally' ; } } function testReturnCatch () { try { throw new Exception ( 'foo' ); } catch ( Exception $e ) { echo 'Within catch' , "\n" ; return 'catch' ; } final ... ly { echo 'Within finally' , "\n" ; return 'finally' ; } } echo testReturnTry (), "\n" ; echo testReturnCatch (), "\n" ; 上の例の出力は以下となります。 Within try Within finally finally Within catch Within finally finally 例4 finall ... ロックと return の相互作用 <?php function testReturnTry () { try { return 'try' ; } finally { echo 'finally ' ; } } function testReturnCatch () { try { throw new Exception ( 'foo' ); } catch ( Exception $e ) { return 'catch' ; } finally { echo 'finally ' ; } } ec ...
https://man.mtool.work/php/8.3/control-structures.finally.html
PREV 1 NEXT