NoDiscard アトリビュートはじめにこのアトリビュートは、関数やメソッドの戻り値を無視すべきでないことを示すために使います。 戻り値がまったく使われなかった場合、警告が発生します。 これは、戻り値を確認しないことがバグにつながる可能性が高い関数に役立ちます。 このような関数の戻り値を意図的に無視するには、(void) キャストを使って警告を抑制します。
クラス概要
#[\Attribute]
final
NoDiscard
/* プロパティ */
public
readonly
stringnull
$message;
/* メソッド */
public __construct(stringnull
$message = null)プロパティ
例例1 基本的な使い方 上の例の PHP 8.5 での出力は、たとえば以下のようになります。: Warning: The return value of function bulk_process() should either be used or intentionally ignored by casting it as (void), as processing might fail for individual items 例2 戻り値を意図的に無視する 参考
|