Jump to content

Question on PHP variable allocation


bigD

Recommended Posts

I have a question on when PHP will allocate space in the code.  Does it happen up front, or as the code executes?

 

// some stuff

if (some_conditional)
{
     // something happens here and returns or exits
}

// we never get here

$foo = array();

exit(0);

 

In this example, does $foo get created?

Link to comment
https://forums.phpfreaks.com/topic/213330-question-on-php-variable-allocation/
Share on other sites

No.  $foo is not created.

 

<?php
// some stuff

if (some_conditional)
{
     // something happens here and returns or exits
     echo var_export( isset( $foo ), true ) . PHP_EOL;
     exit();
}

// we never get here

$foo = array();

exit(0);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.