El atributo Deprecated

(PHP 8 >= 8.4.0)

Introducción

Este atributo se utiliza para marcar la funcionalidad como obsoleta. El uso de funcionalidad obsoleta hará que se emita un error E_USER_DEPRECATED.

Sinopsis de la Clase

#[\Attribute]
final class Deprecated {
/* Propiedades */
public readonly ?string $message;
public readonly ?string $since;
/* Métodos */
public __construct(?string $message = null, ?string $since = null)
}

Propiedades

message

Un mensaje opcional que explica la razón de la deprecación y la posible funcionalidad de reemplazo. Se incluirá en el mensaje de deprecación emitido.

since

Una cadena opcional que indica desde cuándo la funcionalidad está deprecada. El contenido no es validado por PHP y puede contener un número de versión, una fecha o cualquier otro valor que se considere apropiado. Se incluirá en el mensaje de deprecación emitido.

La funcionalidad que es parte de PHP utilizará Major.Minor como el valor de since, por ejemplo '8.4'.

Ejemplos

<?php

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

unsafe_function();

?>

La salida del ejemplo anterior en PHP 8.4 es similar a:

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

Tabla de contenidos

add a note

User Contributed Notes 1 note

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