The Deprecated attribute

(PHP 8 >= 8.4.0)

简介

This attribute is used to mark functionality as deprecated. Using deprecated functionality will cause an E_USER_DEPRECATED error to be emitted.

类摘要

#[\Attribute]
final class Deprecated {
/* 属性 */
public readonly ?string $message;
public readonly ?string $since;
/* 方法 */
public __construct(?string $message = null, ?string $since = null)
}

属性

message

An optional message explaining the reason for the deprecation and possible replacement functionality. Will be included in the emitted deprecation message.

since

An optional string indicating since when the functionality is deprecated. The contents are not validated by PHP and may contain a version number, a date or any other value that is considered appropriate. Will be included in the emitted deprecation message.

Functionality that is part of PHP will use Major.Minor as the since value, for example '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
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