faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

67 of 138 people (49%) answered Yes
Recently 6 of 10 people (60%) answered Yes


Passing variables with REQUIRE function (part II)
In http://www.faqts.com/knowledge-base/view.phtml/aid/1205/fid/40 it is stated that require 'copies'

Mar 15th, 2008 21:16
dman, ha mo, Praveen Kumar Kukkapalli, Cinley Rodick, Matt Gregory, Bjarke Bisgaard Blendstrup, http://www.ttnr.org

Since there is no question here, I'm going to assume that you are 
asking what coppies means.
If this is indeed your question, then the answer would be that the php 
script loaded by the require function effectively is parsed in-line 
where the require function is called.
For instance: let's pretend you have 5 lines of code over 2 files:
$yadda="y pues nada";
$yadda="bite me";
functions would be parsed in the following order:
1.) globals.phtml is parsed and loaded with mytest.phtml, parse errors 
will be found before any script execution even if they are in 
2.) new variable $hoopy is allocated and assigned the value of
3.) $hoopy is re-assigned the value of "dude".
4.) $yadda is allocated and assigned the value of "bite me".
5.) $yadda is reassigned the value of "y pues nada";
So, as you see, the script engine runs on 1 file, the conbination of 
the previous two, while the parser sees two files.  Therefore any 
scripting is executed in-line (unless of course you happen to have 
functions, in which case: make sure they aren't within other functions 
or else you will have a parse error.
Rule of thumb: put everything inside of a script which will be included 
in require statements inside of functions.