Deprecated アトリビュート

(PHP 8 >= 8.4.0)

はじめに

このアトリビュートは、機能を非推奨としてマークします。 マークされた機能を使用すると、E_USER_DEPRECATED エラーが発生します。

クラス概要

#[\Attribute]
final class Deprecated {
/* プロパティ */
public readonly ?string $message;
public readonly ?string $since;
/* メソッド */
public __construct(?string $message = null, ?string $since = null)
}

プロパティ

message

非推奨となった理由と可能なら代替機能を説明する追加のメッセージ。 発生する非推奨エラーのメッセージに含まれます。

since

機能がいつから非推奨になったかを示す追加の文字列。 内容は PHP によって検証されず、バージョン番号、日付、 または適切と考えられる他の値を含むことができます。 発生する非推奨エラーのメッセージに含まれます。

PHP 自体の機能は、since の値として Major.Minor を利用します。 例えば '8.4' です。

<?php

#[\Deprecated(message: "use safe_replacement() instead", since: "1.5")]
function
unsafe_function()
{
echo
"This is unsafe", PHP_EOL;
}

unsafe_function();

?>

上の例の PHP 8.4 での出力は、たとえば以下のようになります。:

Deprecated: Function unsafe_function() is deprecated since 1.5, use safe_replacement() instead in example.php on line 9
This is unsafe

目次

add a note

User Contributed Notes 1 note

up
0
razvan_bc at yahoo dot com
8 days ago
It is a useful function if you have written macro functions = PHP enhanced and with a series of parameters (custom macro compiler) you compile -like me - from the project (several php files,media)->website /app in multiple ways: production, developing=debuging.
otherwize would be like with the guys who write minified JS and generate JS and map and include them in production: while.map is intended for debugging in the developing phase, it is not intended for production (you don't put untested code in production and the badge on the chest of "pro").
If a password is wrong, if an extension is missing, it stops working: DO NOT PUT THE LOG ON THE SCREEN !! DON'T PUT "CONTACT ADMINISTRATOR @"! DON'T GIVE FEEDBACK TO ATTACKERS SO THAT THEY CAN INCREASE THE EFFECTIVENESS OF ATTACKS!!!
This is PHP and that's how it should stay..
To Top