What does the unassigned static variable in PHP contain and why it prints blank space in a browser output window? -


i've following code snippet, please have close on :

<!doctype html> <html>   <body>    <?php     function mytest() {       static $x;       echo $x;       $x++;     }      mytest();     echo "<br>";     mytest();     echo "<br>";     mytest();    ?>     </body> </html> 

note : name of file contains above code demo.php , location on laptop c:\xampp\htdocs\php_playground\demo.php

the output received when run above program browser hitting url http://localhost/php_playground/demo.php below :

1 2  

the screenshot of same attached, please have @ it. output in browser window

  1. my question why first line in output blank containing white space only?
  2. why it's not printing 0 or word "null" or "empty" that?
  3. what unassigned static variable in php contain?
  4. does default value of static unassigned variable , default value of unassigned normal variable differ?

please give me suitable answer proper explanation.

an unassigned variable in php cast null.

<?php echo null; ?> doesn't echo anything, since null has no value.

from null page of php documentation (emphasis mine) :

the special null value represents variable no value. null possible value of type null.

a variable considered null if:

  • it has been assigned constant null.

  • it has not been set value yet.

  • it has been unset().

try replacing echo $x; var_dump($x) in snippet, output following :

null int(1) int(2) 

try it


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -