?
Solved

PHP Require_Once

Posted on 2007-12-06
9
Medium Priority
?
252 Views
Last Modified: 2013-12-23
What is the difference in the require and require_one ? Alos what does the 'new' accomplish in this statement - $bsdconfig = new bsdConnect; (a function command).

Thanks,
Michael
0
Comment
Question by:mhoggatt1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 680 total points
ID: 20422504
>> What is the difference in the require and require_one ?
The are the same with the only difference that if a file has already been included, require_one will not be included again.


>>what does the 'new' accomplish in this statement - $bsdconfig = new bsdConnect; (a function command).

creates an new instance of Class bsdConnect
0
 
LVL 10

Assisted Solution

by:wildzero
wildzero earned 660 total points
ID: 20422516
If you do this
<?PHP
  require('myfile.php');
  // some php
  require('myfile.php');
?>

then it will fail on the second myfile.php because it has already been 'included'.
However if you use
<?PHP
  require_once('myfile.php');
  // some php
  require_once('myfile.php');
?>

then it will not fail as it says, this file has already been 'included' so dont need to again.

new creates a new object instance of bsdConnect

0
 
LVL 10

Expert Comment

by:wildzero
ID: 20422523
well done :-)
0
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
LVL 21

Assisted Solution

by:nizsmo
nizsmo earned 660 total points
ID: 20422527
For the require and require once question, the difference is that using require we can include the same file more than once, while require_once makes sure the file is included only once, even though you have have tried to include the same file more than once.

Hope this helps.
0
 

Author Comment

by:mhoggatt1
ID: 20423055
Thanks guys,
It seems the lst cmment is opposite from the first 2. Can ya'll clarify or am I reading it wrong ?

Thanks
0
 
LVL 10

Expert Comment

by:wildzero
ID: 20423087
No it's right :-)
My comment was a bit wrong, it wouldn't fail unless it contained a php function (then you would get a function already decleared error).

usually you would use require_once on a php file of functions or database connection or class's etc.
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20423093
hmm maybe it is my bad english, but if you were talking about my explanation, it means the same as wildzero and steelseth's. hope this helps :)
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 20423102
I cant understand what is saying but my comments are 100%

wildzero's comment are also correct except that bit, sort off
"then it will not fail as it says"
0
 

Author Comment

by:mhoggatt1
ID: 20424393
Thanks wildzero, that clears up my question on the subject. Ya'll keep up the good work. I'm sure I'll be calling again !

Michael
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question