Атрибут 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 момент устаревания в виде мажорной и минорной версий, например '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

Содержание

Добавить

Примечания пользователей 1 note

up
0
razvan_bc at yahoo dot com
5 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