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

338
Vistas
Does writing $x; mean anything in PHP?

To create a variable x with the value 12345 in PHP, we do the following:

<?php
    $x = 12345;
?>

But let's say that we wrote $x; without assigning it a value:

<?php
    $x;
?>

Does the above code causes anything to happen, or does PHP treat the above $x; as non-existent? for example is the above code effectively the same as the following empty code?:

<?php

?>
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

<?php
    $x;
?>

These line of code mean you just initialize a variable name called x. but you doesn't assign value. But it will use some memory.

You can check use of memory:

<?php
$x;
echo memory_get_usage($x);
?> 

Your Empty CODE :

<?php

?>

These line of code means you just initialize PHP script. But inside there is nothing actually. But it also use some memory.

You can check use of memory:

<?php
echo memory_get_usage();
?>

Hope you understand the difference.

over 4 years ago · Santiago Trujillo Denunciar

0

If you look at what are the defined variables in the following script...

print_r(get_defined_vars());
$x;
print_r(get_defined_vars());
$x = 1;
print_r(get_defined_vars());

You can see that just using $x; doesn't define the variable, it only shows up after assigning it a value. So effectively this is the same as doing nothing.

Also checking the opcodes being generated...

With $x=1; - phpdbg -p* a.php

function name: (null)
L1-4 {main}() /home/nigel/a.php - 0x7f2f36c8e000 + 3 ops
 L3    #0     EXT_STMT                                                                              
 L3    #1     ASSIGN                  $x                   1                                        
 L4    #2     RETURN<-1>              1                                                             

with $x; - phpdbg -p* a.php

function name: (null)
L1-4 {main}() /home/nigel/a.php - 0x7f5898079050 + 2 ops
 L4    #0     EXT_STMT                                                                              
 L4    #1     RETURN<-1>              1  

So it looks as though no opcode is generated.

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