O atributo Deprecated

(PHP 8 >= 8.4.0)

Introdução

Este atributo é usado para marcar uma funcionalidade como descontinuada. Usar uma funcionalidade descontinuada causará a emissão de um erro E_USER_DEPRECATED.

Resumo da classe

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

Propriedades

message

Uma mensagem opcional explicando o motivo da descontinuação e a possível funcionalidade de substituição. Será incluída na mensagem de descontinuação emitida.

since

Uma string opcional que indica desde quando a funcionalidade foi descontinuada. Os conteúdos não são validados pelo PHP e podem conter um número de versão, uma data ou qualquer outro valor que seja considerado apropriado. Será incluída na mensagem de descontinuação emitida.

A funcionalidade que fizer parte do PHP usará a versão principal.secundária como o valor de since, por exemplo '8.4'

Exemplos

<?php

#[\Deprecated(message: "use safe_replacement() instead", since: "1.5")]
function
unsafe_function()
{
echo
"Isto não é seguro", PHP_EOL;
}

unsafe_function();

?>

A saída do exemplo acima no PHP 8.4 é semelhante a:

Deprecated: Function unsafe_function() is deprecated since 1.5, use safe_replacement() instead in example.php on line 9
Isto não é seguro

Índice

adicionar nota

Notas de Usuários 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