473,385 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Wich one is best ?

I have a script where a If condition takes some lines like 30 or something,
my question is if its better to let those 30 lines part of the main script
or to put them in a include file.

Ex.

I have my script like this

....

IF (something) {my 20 lines of code}

...

Wouldn't it be better to have like this

....

IF (something) {include ("file.inc")

....

This way, it wouldn't always parse the 30 lines, but maybe it wouldn't be
faster or even slower as it would take some time to access the file.
Jul 17 '05 #1
5 1615
Marco wrote:
I have a script where a If condition takes some lines like 30 or something,
my question is if its better to let those 30 lines part of the main script
or to put them in a include file.

I have my script like this
IF (something) {my 20 lines of code} Wouldn't it be better to have like this
IF (something) {include ("file.inc")


I believe that php will do the include anyway. IIRC it has to parse all
the includes in case they define functions which you rely on in your code.

Classic case for a subroutine though.

Jul 17 '05 #2

"Kevin Thorpe" <ke***@pricetrak.com> wrote in message
news:40**********************@news.easynet.co.uk.. .
Marco wrote:
I have a script where a If condition takes some lines like 30 or something, my question is if its better to let those 30 lines part of the main script or to put them in a include file.

I have my script like this
IF (something) {my 20 lines of code}

Wouldn't it be better to have like this
IF (something) {include ("file.inc")


I believe that php will do the include anyway. IIRC it has to parse all
the includes in case they define functions which you rely on in your code.

Classic case for a subroutine though.


I see, i've read some other comments here saying that its faster to have it
in a single file than having to open and close include files.

Thx

Marco
Jul 17 '05 #3
So, what is your question about then if you already know what's gonna be
said?

Nevermind.

Kevin is right. The includes wil happen anyway and unless you're writing
some code that is looped over and over again, it will be included everytime
you execute your code.

However, if you loop code, you'll want to include (once) instead of list....
this'll save time.... of use a function instead of your lines o' code

Regards,

MIchel
"Marco" <mpgtlatbluewindotch> wrote in message
news:40**********@news.bluewin.ch...

"Kevin Thorpe" <ke***@pricetrak.com> wrote in message
news:40**********************@news.easynet.co.uk.. .
Marco wrote:
I have a script where a If condition takes some lines like 30 or something, my question is if its better to let those 30 lines part of the main script or to put them in a include file.

I have my script like this
IF (something) {my 20 lines of code}
Wouldn't it be better to have like this
IF (something) {include ("file.inc")


I believe that php will do the include anyway. IIRC it has to parse all
the includes in case they define functions which you rely on in your code.
Classic case for a subroutine though.


I see, i've read some other comments here saying that its faster to have

it in a single file than having to open and close include files.

Thx

Marco

Jul 17 '05 #4
On Wed, 18 Feb 2004 11:02:14 +0100, michel wrote:
So, what is your question about then if you already know what's gonna be
said?

Nevermind.

Kevin is right. The includes wil happen anyway and unless you're writing
some code that is looped over and over again, it will be included everytime
you execute your code.


It's probably too late for the OP to read this, but I'll post this reply
anyway in the hope that this incorrect information will not propagate.
Kevin is not right. In the example below, "b.php" will not be included.
You can easily test this yourselves. To answer the question of the OP,
under certain conditions it can be advantageous to conditionally include a
file.

<?php
//--test.php

if (1 == 1)
include('a.php');
else
include('b.php');

echo b();
?>

<?php
//--a.php
function a() {
return 'This is function a';
}
?>

<?php
//--b.php
function b() {
return 'This is function b':
}
?>


Jul 17 '05 #5

"Henk Burgstra" <eg****@xs4all.nl> wrote in message
news:pa****************************@xs4all.nl...
On Wed, 18 Feb 2004 11:02:14 +0100, michel wrote:
So, what is your question about then if you already know what's gonna be
said?

Nevermind.

Kevin is right. The includes wil happen anyway and unless you're writing
some code that is looped over and over again, it will be included everytime you execute your code.


It's probably too late for the OP to read this, but I'll post this reply
anyway in the hope that this incorrect information will not propagate.
Kevin is not right. In the example below, "b.php" will not be included.
You can easily test this yourselves. To answer the question of the OP,
under certain conditions it can be advantageous to conditionally include a
file.

<?php
//--test.php

if (1 == 1)
include('a.php');
else
include('b.php');

echo b();
?>

<?php
//--a.php
function a() {
return 'This is function a';
}
?>

<?php
//--b.php
function b() {
return 'This is function b':
}
?>


Its never too late ;)
Indeed it doesnt parse the file if it doesnt match the IF statement, we can
see it too by not making the file b.php of your example, if the PHP engine
tryed to parse this file he would give a error and thats not the case.
Jul 17 '05 #6

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

Similar topics

0
by: Richard Zierhut | last post by:
Hello, I just started to get in touch with php and use it as extension of my Java Applets..... How can I open a URL wich is of this kind: http://www.host.com/?alotofdata
1
by: Gilles Cadorel | last post by:
On a PC, we've got 2 different releases of Oracle Client installed. We have softwares that don't ask during the install wich release of Oracle must be used. When we launch these softwares, how can...
3
by: Christian Ista | last post by:
Hello, Which version (pro, architect, ....) of VS 2005 is available for download for MSDN Universal subscriber ? Thanks,
5
by: bredal Jensen | last post by:
Hello, I have a web form with three buttons among other things. I need to know wich one of my buttons was pressed . The problem is that i want my page to be valid before any of the buttons...
9
by: Crirus | last post by:
Just simple mails plain text -- Ceers, Crirus ------------------------------ If work were a good thing, the boss would take it all from you ------------------------------
8
by: Tjerk Wolterink | last post by:
I have xml inpput like this: <meta:empty/> And xsl like this: <xsl:template match="meta:empty">A</xsl:template> <xsl:template match="//meta:*">B</xsl:template>
5
by: Joris De Groote | last post by:
Hi, I have a question, wich goes faster (The table has 15000 rows in it and growing every day)? - at the start of the program run a querry and put this in a dataset and during the program...
3
by: BLUE | last post by:
Only SQL Server 2005 or also DB2, Oracle and MySQL? Thanks, Luigi.
1
by: thirunavukarasukm | last post by:
I have a link wich opens a the second page with links wich call a javascript function. I have some problem with javascript. i am two aspx page.. in my first aspx page contain the second...
2
by: Erland Sommarskog | last post by:
lopina (ivica.lopar@email.t-com.hr) writes: I'm afraid I don't really get your problem. This is legal: create table ferenc (a int NULL DEFAULT NULL) Then again, even without an explicit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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,...

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.