PHP: Parser behavior - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Error reporting Migrating Configuration Files

Last updated: Sat, 27 Jan 2007

view this page in

# Parser behavior

Parsing and execution are now two completely separated steps, no execution of a files code will happen until the complete file and everything it requires has completely and successfully been parsed.

One of the new requirements introduced with this split is that required and included files now have to be syntactically complete. You can no longer spread the different controlling parts of a control structure across file boundaries. That is you cannot start a `for` or `while` loop, an `if` statement or a `switch` block in one file and have the end of loop, `else`, `endif`, `case` or `break` statements in a different file.

It still perfectly legal to include additional code within loops or other control structures, only the controlling keywords and corresponding curly braces `{...}` have to be within the same compile unit (file or eval()ed string).

This should not harm too much as spreading code like this should be considered as very bad style anyway.

Another thing no longer possible, though rarely seen in PHP 3 code is returning values from a required file. Returning a value from an included file is still possible.

add a note User Contributed Notes
Parser behavior
alan at frostick dot de
02-Dec-2001 10:31
`Although I reported this in the early days of php4 release as a migration problem, it has yet to appear in the manual. So add this note to clarify things for newcomers to php4 conversions.
An apparent parser change occurred between php3 and php4 to the function unset(). There are now lots of maybe confusing comments about this in the manual under this functions page which you should read.
To clarify an important difference which I spotted, the behaviour of unset() when used within a function on static or global variables gives quite different effects. In php3 the values of such variables were simply reset whereas now the variable is completely removed and any subsequent reference to the same variable name results in a completely new variable being defined - ie. a local function variable is created.
Some misunderstandings about the original php3 function are obvious amongst non-php authors. Quite possibly the present php4 interpretation is what was originally intended in php3, but since it was not implemented in this way can give rise to shocks when the same scripts are run under php4.
e.g.
function foo()
{
global $bar;
// at this point $bar is global
$bar="assign this string";
unset($bar);
// at this point $bar is local
$bar="overwrite string";
// so this assignment does not affect the global}
foo(); echo $bar;
Under php3 you would get "overwrite string", but under php4 "assign this string".
A similar difference occurs using unset to wipe out an array. The variable is no longer an array, and the memory used by the array is not released for re-use. You are advised to replace any uses of:
unset($arr);
by instead
$arr=array();`
add a note
Error reporting Migrating Configuration Files

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST