Wrox Programmer Forums
|
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 13th, 2003, 12:48 PM
Authorized User
 
Join Date: Aug 2003
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tachyon
Default help with page 223 - file includes

Hello, everyone.
I'm having trouble understanding the bottom of page 223. It says when using include files we have to guard against calling on the same function twice. It offers a solution - some code to guard against the problem.

... declare a variable in every include file you create:
$COMMON_INCLUDED=1;

and then test for it at the beginning of the include:
if (!$COMMON_INCLUDED) $COMMON_INCLUDED=1;


I don't understand this very well. Could someone please explain this to me? Does this mean that each file you include should have $COMMON_INCLUDED=1; in it? I don't understand what the 2nd line of code does or what it means.

Any help would be greatly appreciated.

__________________
An overworked Web Developer who\'s expected to know everything yet given time to study nothing.
 
Old August 14th, 2003, 01:55 AM
Authorized User
 
Join Date: Jul 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That looks strange to me too. I think they want the include file to have a variable (they're using a name similar to the file here) that is set to a one within the include file. They then test to see if that variable has been set true, meaning it's been included already.

I think they meant to write in that second line:
if (!$COMMON_INCLUDED) include("common.inc");

Oregon
 
Old August 14th, 2003, 08:56 AM
Authorized User
 
Join Date: Aug 2003
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tachyon
Default

Thanks for the reply. I was scratching my head for the longest time trying to figure out how that line of code in the book helped anything. I'm going to look over your code sample again and see if I can come to grips with this issue.

 
Old August 14th, 2003, 12:59 PM
Authorized User
 
Join Date: Jul 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I suppose you could also test for the $COMMOM_INCLUDED variable upon entry into the include file. If the file HAS been included already, you could just bypass the functions, like with a big IF statement within the include file.
I guess you already know that the '!' used before a variable means "if not true (ie isn't set)". Anyway, good luck!

Oregon






Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic XML file from asp includes jfergy Classic ASP Professional 0 April 7th, 2006 02:20 AM
ASP Includes in XSL Alexpizzoferro XSLT 1 June 2nd, 2005 02:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.