By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,748 Members | 1,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,748 IT Pros & Developers. It's quick & easy.

Public response to A Kaufman

P: n/a
Dear A Kaufman, I can't IMAGINE what you mean by this post in one previous
thread.

=================================================
"An include/require will be included no matter what.

For example:
<?php
if(TRUE){
include "myfile.php";
} else {
include "yourfile.php";
}
?>

In the above example - BOTH files will be included no matter what."
=================================================

This is NOT OF COURSE the case!

http://perttu.finote.com/muuta/test.php

Here I have in same folder files myfile.php and yourfile.php, other one
echoing
This text comes from file myfile.php
and other one echoing
This text comes from file yourfile.php

but OF COURSE test.php prints only "This text comes from file myfile.php"
Feb 1 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On 1 Feb, 11:14, "P Pulkkinen"
<perttu.POISTATAMA.pulkki...@POISTATAMA.elisanet.f iwrote:
Dear A Kaufman, I can't IMAGINE what you mean by this post in one previous
thread.

=================================================
"An include/require will be included no matter what.

For example:
<?php
if(TRUE){
include "myfile.php";} else {

include "yourfile.php";}

?>

In the above example - BOTH files will be included no matter what."
=================================================

This is NOT OF COURSE the case!

http://perttu.finote.com/muuta/test.php

Here I have in same folder files myfile.php and yourfile.php, other one
echoing
This text comes from file myfile.php
and other one echoing
This text comes from file yourfile.php

but OF COURSE test.php prints only "This text comes from file myfile.php"
He did not say that the contents of both files would be executed, he
said that both files would be included. The if/then/else statement
will ensure that the contents of yourfile.php do not get executed,
however they WILL be included.

Feb 1 '07 #2

P: n/a
P Pulkkinen wrote:
Dear A Kaufman, I can't IMAGINE what you mean by this post in one previous
thread.
My bad. I'm still thinking the old way.
I really wish I'd known they'd changed it - because this would
have come in handy a LOT over the last little while.

Here's the section from the PHP docs:

Note: Prior to PHP 4.0.2, the following applies: require()
will always attempt to read the target file, even if the line
it's on never executes. The conditional statement won't affect
require().
Feb 1 '07 #3

P: n/a
"Captain Paralytic" <pa**********@yahoo.comwrote in message
news:11********************@l53g2000cwa.googlegrou ps.com...
On 1 Feb, 11:14, "P Pulkkinen"
<perttu.POISTATAMA.pulkki...@POISTATAMA.elisanet.f iwrote:
>Dear A Kaufman, I can't IMAGINE what you mean by this post in one
previous
thread.

=============================================== ==
"An include/require will be included no matter what.

For example:
<?php
if(TRUE){
include "myfile.php";} else {

include "yourfile.php";}

?>

In the above example - BOTH files will be included no matter what."
=============================================== ==

This is NOT OF COURSE the case!

http://perttu.finote.com/muuta/test.php

Here I have in same folder files myfile.php and yourfile.php, other one
echoing
This text comes from file myfile.php
and other one echoing
This text comes from file yourfile.php

but OF COURSE test.php prints only "This text comes from file
myfile.php"

He did not say that the contents of both files would be executed, he
said that both files would be included. The if/then/else statement
will ensure that the contents of yourfile.php do not get executed,
however they WILL be included.
A proper way to test it might be including a HUGE (like Donald Trump Huge) a
file and see if there's a performance peak... like this:

<?php

$started = time();

if(FALSE){
require('my_huge_1Gb_bogus_file.php');
}
echo 'elapsed = '.(time()-$started);

?>

I'm thinking if elapsed time jumps thru the roof, then the file was accessed
and read into memory, but not executed thou. my_huge_1Gb_bogus_file.php
could just be <?php /* LOL OMG THIS IS A TEST LOL OMG THIS IS A TEST LOL OMG
THIS IS A TEST .... */ ?repeated a zillion times so that the file size
would actually become gigantic.

Another thing is that if you use require and a non-existing file, php
doesn't throw an error if the require statement is unreachable, like behind
if(FALSE), only when the file really is included in the code.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Feb 1 '07 #4

P: n/a

Another thing is that if you use require and a non-existing file, php
doesn't throw an error if the require statement is unreachable, like behind
if(FALSE), only when the file really is included in the code.
Sorry, people, to disturb you, but if php attempts to scan every
include()'d or require()'d file, how it deals with such construct?

if (false) {
$fileName = 'someFile.php';
include($fileName);
}

Even if include statement is processed, the $fileName var won't be
initialized before that point! I used such construct a lot, and
haven't get any errors or messages! Or even slowdonws! And you can
include/require you files in a loop, continiuosly changing the
filename or many other ways... so I think that PHP does not behave
that way, it does not process includes or requires that are not in the
execution thread.

Feb 2 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.