473,497 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how does php parse actually this?

suppose i have the following code:

switch ($inc):
case 0:
require 'inc0.php';
break;
case 1:
require 'inc1.php';
break;
case 2:
require 'inc2.php';
break;
endswitch;

question:
does php actually include and parse all 3 files, or just the one needed
(isuppose so, but i'm not sure)? how does that influence performance
(each inc is about 40k)?

micha

Jul 17 '05 #1
7 1740
chotiwallah wrote:
suppose i have the following code:

switch ($inc):
case 0:
require 'inc0.php';
break;
case 1:
require 'inc1.php';
break;
case 2:
require 'inc2.php';
break;
endswitch;

question:
does php actually include and parse all 3 files, or just the one
needed (isuppose so, but i'm not sure)? how does that influence
performance (each inc is about 40k)?


Only the one needed will be included in your script. Both include() and
require() work pretty much the same way except require() will produce a
fatal error if the file could not be included, whereas include() will
just show a warning on error.

I think the behaviour was changed from PHP4 on, as I'm pretty sure in
PHP3 require() included the file regardless of any conditional code.

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Jul 17 '05 #2
chotiwallah wrote:
suppose i have the following code:

switch ($inc):
case 0:
require 'inc0.php';
break;
case 1:
require 'inc1.php';
break;
case 2:
require 'inc2.php';
break;
endswitch;
This doesn't exactly look like php...
question: does php actually include and parse all 3 files, or just
the one needed (isuppose so, but i'm not sure)? how does that
influence performance (each inc is about 40k)?


Just read the documentation:
http://nl.php.net/manual/en/function.require.php

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(). However, if
the line on which the require() occurs is not executed, neither will any
of the code in the target file be executed. Similarly, looping
structures do not affect the behaviour of require(). Although the code
contained in the target file is still subject to the loop, the require()
itself happens only once.

--
"He who asks a question is a fool for five minutes;
he who does not ask a question remains a fool forever"
Jul 17 '05 #3
Hans van Kranenburg wrote:
chotiwallah wrote:
suppose i have the following code:

switch ($inc):
case 0:
require 'inc0.php';
break;
case 1:
require 'inc1.php';
break;
case 2:
require 'inc2.php';
break;
endswitch;

This doesn't exactly look like php...

question: does php actually include and parse all 3 files, or just
the one needed (isuppose so, but i'm not sure)? how does that
influence performance (each inc is about 40k)?

Just read the documentation:
http://nl.php.net/manual/en/function.require.php

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(). However, if
the line on which the require() occurs is not executed, neither will any
of the code in the target file be executed. Similarly, looping
structures do not affect the behaviour of require(). Although the code
contained in the target file is still subject to the loop, the require()
itself happens only once.


Uhm... sorry, this is not exactly the right quote... :P Anyway,
including all files whether they are on a line of code that will be
executed smells like asp behaviour, and the above makes clear that PHP
doesn't act like that anymore since 4.0.2

--
"He who asks a question is a fool for five minutes;
he who does not ask a question remains a fool forever"
Jul 17 '05 #4
On Fri, 13 May 2005 02:24:21 +0200, Hans van Kranenburg <f0****@xs4all.nl>
wrote:
chotiwallah wrote:
suppose i have the following code:

switch ($inc):
case 0:
require 'inc0.php';
break;
case 1:
require 'inc1.php';
break;
case 2:
require 'inc2.php';
break;
endswitch;


This doesn't exactly look like php...


It's valid - it's the "alternative control structure syntax".

This has its occasional uses for the situation when you've got a simple
conditional around a chunk of literal HTML, where the literal HTML makes up the
majority of your file e.g.:

<?php if ($something) : ?>

stuff goes here

<?php endif; ?>
Arguably more readable than:
<?php if ($something) { ?>

stuff goes here

<? } ?>
... as the } in its own little bit of PHP is somewhat cryptic. Wouldn't use it
in plain blocks of PHP as per the OP's post, though.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #5
Andy Hassall wrote:
On Fri, 13 May 2005 02:24:21 +0200, Hans van Kranenburg <f0****@xs4all.nl>
wrote:
It's valid - it's the "alternative control structure syntax".

This has its occasional uses for the situation when you've got a simple
conditional around a chunk of literal HTML, where the literal HTML makes up the
majority of your file e.g.:

<?php if ($something) : ?>

stuff goes here

<?php endif; ?>
Arguably more readable than:
<?php if ($something) { ?>

stuff goes here

<? } ?>
... as the } in its own little bit of PHP is somewhat cryptic. Wouldn't use it
in plain blocks of PHP as per the OP's post, though.

I ceased using this syntax a couple of years ago having been instructed
that it was outdated, PHP peculiar and likely to be dropped in later
versions of PHP. Was this wrong? It certainly produces cleaner
scripting on occasion.

Louise
Jul 17 '05 #6
On Sat, 14 May 2005 04:59:01 GMT, boclair <bo*****@bigpond.net.au> wrote:
It's valid - it's the "alternative control structure syntax".

<?php if ($something) : ?>

stuff goes here

<?php endif; ?>
I ceased using this syntax a couple of years ago having been instructed
that it was outdated, PHP peculiar and likely to be dropped in later
versions of PHP. Was this wrong? It certainly produces cleaner
scripting on occasion.


I don't recall ever reading anything implying it'd be dropped, and it's still
there in PHP5. There's no warnings to this effect in the manual that I can see.

It would be incredibly foolish of the PHP maintainers to drop this since it'll
simply break scripts, with no actual benefit to removing the functionality.

Where did you hear this information? I've found this article:

http://www.zend.com/zend/art/mistake...ew=1#Heading23

Which says:

" * It is not widely used, and therefore, many people learning the language
will be confused by the two syntaxes. "

There are many built-in functions that are not widely used, but that shouldn't
stop you using the appropriate one for the task in hand. The alternative
structure syntax has a particular niche in the type of output posted earlier;
it's not much good in blocks of PHP (as in the article), but it's useful in
specific situations. I'd argue that:

<?php } ?>

... confuses new starters more than:

<?php endif; ?>

... in the "conditional around blocks of literal text" situation.
" * It is not compatible with other languages, meaning that it is harder to
read for people who are transitioning. "

So? PHP's not compatible with Python's method of control structures either.

(And what will people be transitioning from, anyway? ASP? In which case -
they'll prefer endif...)
" * Most importantly, someday in the future it might be disabled, forcing you
to rewrite the code that implemented it. Brackets, however, will always be a
part of the PHP language. "

Without a reference to a documented warning that it's deprecated, this doesn't
count. The article was written in 2000, five years later they're still there
and still useful in a very specific situation.

There are deprecated features in PHP, such as accessing characters within a
string using [] instead of {} ($string[1] is deprecated but works, $string{1}
is supposed to be the way to go). This is documented:

http://uk2.php.net/manual/en/languag....string.substr

They say it's deprecated in PHP4, so they'd have some leeway for removing it
in PHP5. They haven't though.

I see no similar warning for the alternative control structure syntax. I'm
certainly not going to stop using it in the specific situations where it is
more readable.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #7
Andy Hassall wrote:
On Sat, 14 May 2005 04:59:01 GMT, boclair <bo*****@bigpond.net.au> wrote:

It's valid - it's the "alternative control structure syntax".

<?php if ($something) : ?>

stuff goes here

<?php endif; ?>


I ceased using this syntax a couple of years ago having been instructed
that it was outdated, PHP peculiar and likely to be dropped in later
versions of PHP. Was this wrong? It certainly produces cleaner
scripting on occasion.

I don't recall ever reading anything implying it'd be dropped, and it's still
there in PHP5. There's no warnings to this effect in the manual that I can see.

It would be incredibly foolish of the PHP maintainers to drop this since it'll
simply break scripts, with no actual benefit to removing the functionality.

Where did you hear this information? I've found this article:

http://www.zend.com/zend/art/mistake...ew=1#Heading23

They were comments on one of my projects by a tutor in 2002/3. Looking
back I think comments on method were marked as advisory rather than wrong.

One of the problems I find with programming is discerning from reference
books and other material what is true or biased or just plain wrong;
(not including the Manual, of course).

Thanks for your extended examination of this. Very helpful.

Louise
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
3124
by: | last post by:
Hi, I need to read a big CSV file, where different fields should be converted to different types, such as int, double, datetime, SqlMoney, etc. I have an array, which describes the fields and...
7
6606
by: memememe | last post by:
I need to be able to parse both of these dates with the same method, and return them as a DateTime object. Is there any methods that would do this blindly or do I need to provide the format? Feb...
19
3196
by: Johnny Google | last post by:
Here is an example of the type of data from a file I will have: Apple,4322,3435,4653,6543,4652 Banana,6934,5423,6753,6531 Carrot,3454,4534,3434,1111,9120,5453 Cheese,4411,5522,6622,6641 The...
15
6699
by: Greenhorn | last post by:
Hi, when a function doesn't specify a return type ,value what value is returned. In the below programme, the function sample()is returning the value passed to 'k'. sample(int); main() { int...
3
24363
by: Mark | last post by:
How do you parse a currency string to a decimal? I'd like to avoid having to parse the number out, removing the $ manually. That sounds like a hack. There are times that this string will be...
3
3066
by: Slonocode | last post by:
I have some textboxes bound to an access db. I wanted to format the textboxes that displayed currency and date info so I did the following: Dim WithEvents oBidAmt As Binding oBidAmt = New...
15
27794
by: Brian Henry | last post by:
Which one is better to use? CInt(string) or Integer.Parse(string)? thanks!
8
6128
by: Rico | last post by:
Hello Everyone, I observed something strange in some quick testing code: void Button1Click(object sender, System.EventArgs e) { CultureInfo culture = new CultureInfo("th-TH", false); ...
7
2545
by: pedrito | last post by:
I get exception trying to parse this URI: http://-eeayr4mwvtw998.usercash.com/ But IE and Firefox have no problem opening it. The parse exception is actually happening inside an...
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.