Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

335
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!