Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

337
Vistas
php 8.1 - explode(): Passing null to parameter #2 ($string) of type string is deprecated

Coming across some deprecated errors with 8.1 I want to address.

PHP Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in...

//explode uids into an array
$comp_uids = explode(',', $result['comp_uids']);

$result['comp_uids'] in this case is empty which is why the null error shows. I'm not sure why they are deprecating this ability, but what is the recommended change to avoid this? I'm seeing similar with strlen(): Passing null to parameter #1 ($string) of type string is deprecated and a few others using 8.1.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Use the null coalescing operator to default the value to an empty string if the value is null.

$comp_uids = explode(',', $result['comp_uids'] ?? '');
over 4 years ago · Santiago Trujillo Denunciar

0

There's no need to explode null, you know beforehand that it won't return matches. If you really want [''] as result, it's more intuitive to do it explicit:

$comp_uids = $result['comp_uids'] !== null ? explode(',', $result['comp_uids']) : [''];

I still find this a bit counter-intuitive for your fellow programmers. IMHO, the no UIDs were found concept is better represented by an empty array and, if you can expect empty strings as well, they may well be handled together with null:

$comp_uids = $result['comp_uids'] != '' ? explode(',', $result['comp_uids']) : [];
over 4 years ago · Santiago Trujillo Denunciar

0

Just cast the parameter as string, will convert null to ''.

$comp_uids = explode(',', (string)$result['comp_uids']);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda