Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP 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 May 22nd, 2004, 09:59 AM
Authorized User
 
Join Date: Dec 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default include() vs require()

Concerning Include() and require(), the current php manual states, "The two constructs are identical in every way except how they handle failure."

However, I have read, and found online, "Unlike include(), require() will always read in the target file, even if the line it's on never executes. If you want to conditionally include a file, use include(). The conditional statement won't affect the 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."

Does this second statement only concern earlier versions of PHP, or did I just not find it in the current manual?
 
Old May 23rd, 2004, 07:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My copy of the manual prepends those statements with:

"Prior to PHP 4.0.2, the following applies:"

According to Zeev Suraski (who probably should know these things, if anyone does), "as of PHP 4.0.3, the implementation of require() processes the file 'just in time'"
(http://marc.theaimsgroup.com/?l=php-...97419027907315)
i.e. only if needed. So, nowadays, the lines:

if(false){
    require("page.php");
}

Will neither read nor execute page.php. Ever. This is actually how include always behaved.

HTH
Dan
 
Old May 23rd, 2004, 10:04 PM
Authorized User
 
Join Date: Dec 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dan - Thanks for clearing it up! I now see the "Prior to PHP 4.0.2" note in the require() documentation, but it wasn't quite clear to me the first time I read the note.

I did understand that include() always worked this way, but was reading a book which made me wonder whether I should go back and change some of my require() coding. I know the 2002 publication date of the book should have given me a clue, but sometimes out-of-date web "help" is harder to catch.

Thanks again!

- Steve





Similar Threads
Thread Thread Starter Forum Replies Last Post
require ECDH java code m.ganguli BOOK: Beginning Cryptography with Java 19 December 10th, 2011 11:04 PM
Associating RegularExpressionValidator and Require belete ASP.NET 2.0 Basics 0 October 20th, 2007 10:26 AM
require attribute - all but... kfir XML 2 May 28th, 2006 09:45 AM
difference between include file & include virtual crmpicco Classic ASP Basics 2 January 23rd, 2006 11:50 AM
Problem with include or require cli PHP How-To 2 May 24th, 2005 11:15 AM





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