473,809 Members | 2,819 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 1762
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 "alternativ e 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.andyhsoftwa re.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 "alternativ e 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*****@bigpon d.net.au> wrote:
It's valid - it's the "alternativ e 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 "conditiona l 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.andyhsoftwa re.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*****@bigpon d.net.au> wrote:

It's valid - it's the "alternativ e 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
3180
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 their types. I would like to somehow store a reference to parsing operations in this array (such as Int32.Parse, Double.Parse, SqlMoney.Parse, etc), so I can invoke the appropriate one without writing a long switch.
7
6622
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 25 23:11 Dec 1 2002
19
3228
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 first position is the info (the product) I want to retreive for the corresponding code. Assuming that the codes are unique for each product and all code data is on one line.
15
6736
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 i = 0,j; j = sample(0);
3
24404
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 currency and others when it will be a text integer or decimal. //This bombs because of the string having an improper format. Decimal.Parse("$9,200.00") Thanks in advance! Mark
3
3087
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 Binding("Text", Me.Ds1, "Items.BidAmt") txtBidAmt.DataBindings.Add(oBidAmt) Private Sub oBidAmt_Format(ByVal sender As Object, ByVal e As System.Windows.Forms.ConvertEventArgs) Handles oBidAmt.Format
15
27857
by: Brian Henry | last post by:
Which one is better to use? CInt(string) or Integer.Parse(string)? thanks!
8
6145
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); tbxDisplayResult.Text = DateTime.Parse(tbxInputArea.Text, culture).ToString("yyyy MMMMMMMMMM dd");
7
2563
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 HTTPWebRequest so I guess there's no much I can do about it one wary or the other, unless there's some way to encode it so that it still goes where it's supposed to go but is actually parseable by the URI parser as well.
0
10635
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10378
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.