New question

Question:

Date: 04-02-2025 06:08:50 (In Spanish)

[Aporte] DEPRECATED [8192] str_pad(): Passing null to parameter #1 ($string) of type string is deprecated[Resolved]

Para los que están recibiendo este error:
DEPRECATED [8192] str_pad(): Passing null to parameter #1 ($string) of type string is deprecated

la función str_pad en PHP 8.2 arroja un Deprecated cuando se le pasa un null, para poder permitir null y no tener que modificar en gran medida tu código puedes armar tu propia función que si soporte null (un wrapper de la función original).

Idea con una clase MyHelper:
class MyHelper {

    public static function str_pad(?string $texto, int $length, string $pad_string = " ", int $pad_type = STR_PAD_RIGHT): string {
        return str_pad($texto ?? "", $length, $pad_string, $pad_type);
    }
}

Función 			Reemplazo Recomendado
str_pad(	MyHelper::str_pad(



Para este ejemplo con la clase MyHelper, directamente hace un Ctrl + H en su editor (remplazar) y remplazar por ejemplo "str_pad(" por "MyHelper::str_pad(", y no es necesario intervenir en cada archivo, se hace por remplace.

Saludos y buen código!
Tags: Deprecated features - Input - PHP Votes: 1 - Answers: 0 - Views: 2 Share on: Google Facebook Twitter LinkedIn Link
 

Answers:

No replies for this question, be the first to answer.
To actively participate in the community first must authenticate, enter the system.Sign In
 
frjcbbae garagebible.com