FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Is there any situation where anything other than require_once is better?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Is there any situation where anything other than require_once is better? [message #171927 is a reply to message #171923] Fri, 21 January 2011 17:07 Go to previous messageGo to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma:
Senior Member
On 1/21/2011 11:51 AM, Leonardo Azpurua wrote:
> Hi,
>
> I have so far used "include" (coming from "C", I just saw it and
> understood it).
>
> Then I read about "require" and "require_once."
>
> Ok. I understand that there might be some situations where not being
> able to reach a particular file might not hinder the execution of an
> applicaton (thus rationalizing the existence of "include"), but I hope
> that will never be my case.
>
> So I will rely on "require" over "include".
>
> So far (I am absolutely new to PHP) I have written reusable functions
> that are stored in files in the include folder, and have not needed to
> nest inclusions.
>
> But now I am going to start coding classes, and if they are going to be
> completely context independent, they must declare their own dependencies
> as "require" statements.
>
> And I guess "require_once" is the natural choice for this situation.
>
> Since I care a lot about simplicity, and lexical simpicity is achieved
> by a vocabulary as reduced as possible, I am about to forget the
> existence of "include", "include_once" and "require".
>
> Is there any chance that such voluntary oblivion will get me into
> trouble later (except for the chance to flunk in a certification test
> that I will never take)?
>
> Thanks.

There is a use for require rather than require_once. Suppose, for
example, that you have a drop-down select list of the year (or anything
else). You might very well want to create an include file for all the
options in that list. If you have more than one date control (or any
other type of control that needs the same content), then it becomes a
simple and consistent matter to just define the dropdown and do a
"require" of the contents list file. In this case a "require_once"
would not be appropriate since it needs to be used more than once on the
page.

Otherwise, just use require_once all the time. It is safer. Also, it
will tell you in testing if you have made an error.

--
Shelly
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Syntax for trim charlist?
Next Topic: SNMPv3 for PHP?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 01:33:09 GMT 2024

Total time taken to generate the page: 0.03742 seconds