Loading of required data

Loading of required data

am 02.08.2007 19:22:49 von Armando Padilla

Hi everyone. heres a pretty newbie question ive have a script as shown
below. My question is will the engine load up ALL the required scripts
at run time OR will only the required scripts be loaded when entering an
if statement. Not to answer my own question but i thought the php
engine loaded ALL required files even if they are not being used at
start up.

/**********
* PHP SCRIPT
***********/
require("some file1.php");

$x = 1;

if($x = 1){
/* some code */
require("some other file.php");
}else{
require("some other other file.php"); //Will this also load up in
memory? even if it never is reached?
}

Re: Loading of required data

am 02.08.2007 19:47:23 von gosha bine

Armando Padilla wrote:
> Hi everyone. heres a pretty newbie question ive have a script as shown
> below. My question is will the engine load up ALL the required scripts
> at run time OR will only the required scripts be loaded when entering an
> if statement. Not to answer my own question but i thought the php
> engine loaded ALL required files even if they are not being used at
> start up.
>
> /**********
> * PHP SCRIPT
> ***********/
> require("some file1.php");
>
> $x = 1;
>
> if($x = 1){

sure you mean $x == 1 (BTW to avoid this error in the future, take a
habit of writing a constant first : if(1 == $x)


> /* some code */
> require("some other file.php");
> }else{
> require("some other other file.php"); //Will this also load up in
> memory? even if it never is reached?
> }

php only includes files when the require/include statements are
executed, in other words

$x = 1;

if(1 == $x)
require("include this");
else
require("this-will-be-NEVER-included");




--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

Re: Loading of required data

am 02.08.2007 19:48:58 von luiheidsgoeroe

On Thu, 02 Aug 2007 19:47:23 +0200, gosha bine =

wrote:
> php only includes files when the require/include statements are =

> executed, in other words
>
> $x =3D 1;
>
> if(1 == $x)
> require("include this");
> else
> require("this-will-be-NEVER-included");

Since 4.0.2, then again, anyone running a lower version really should =

upgrade....
-- =

Rik Wasmus

Re: Loading of required data

am 02.08.2007 19:54:12 von Armando Padilla

Rik wrote:
> On Thu, 02 Aug 2007 19:47:23 +0200, gosha bine
> wrote:
>> php only includes files when the require/include statements are
>> executed, in other words
>>
>> $x = 1;
>>
>> if(1 == $x)
>> require("include this");
>> else
>> require("this-will-be-NEVER-included");
>
> Since 4.0.2, then again, anyone running a lower version really should
> upgrade....
Ah ok, thanks. so nothing gets placed into mem if its not reached,
gotcha. I though it was the case that all required docs were called
when creating the intermediate code on the engine and then depending on
the if-else statement the required doc would be executed or not.

Re: Loading of required data

am 02.08.2007 20:09:55 von gosha bine

Armando Padilla wrote:
> Rik wrote:
>> On Thu, 02 Aug 2007 19:47:23 +0200, gosha bine
>> wrote:
>>> php only includes files when the require/include statements are
>>> executed, in other words
>>>
>>> $x = 1;
>>>
>>> if(1 == $x)
>>> require("include this");
>>> else
>>> require("this-will-be-NEVER-included");
>>
>> Since 4.0.2, then again, anyone running a lower version really should
>> upgrade....
> Ah ok, thanks. so nothing gets placed into mem if its not reached,
> gotcha. I though it was the case that all required docs were called
> when creating the intermediate code on the engine and then depending on
> the if-else statement the required doc would be executed or not.
>

That would be cool, but hardly possible, because includes can be (and
mostly are) dynamic:

include $my_file_name;



--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

Re: Loading of required data

am 02.08.2007 23:23:24 von Jerry Stuckle

gosha bine wrote:
> Armando Padilla wrote:
>> Rik wrote:
>>> On Thu, 02 Aug 2007 19:47:23 +0200, gosha bine
>>> wrote:
>>>> php only includes files when the require/include statements are
>>>> executed, in other words
>>>>
>>>> $x = 1;
>>>>
>>>> if(1 == $x)
>>>> require("include this");
>>>> else
>>>> require("this-will-be-NEVER-included");
>>>
>>> Since 4.0.2, then again, anyone running a lower version really should
>>> upgrade....
>> Ah ok, thanks. so nothing gets placed into mem if its not reached,
>> gotcha. I though it was the case that all required docs were called
>> when creating the intermediate code on the engine and then depending
>> on the if-else statement the required doc would be executed or not.
>>
>
> That would be cool, but hardly possible, because includes can be (and
> mostly are) dynamic:
>
> include $my_file_name;
>
>
>

It used to be before PHP 4.0.2. include was processed when the file was
parsed, not when it was executed, just like in other languages such as
C, C++ and Java. PHP is now a little more discriminating :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================