Solved

PHP Require_Once

Posted on 2007-12-06
9
248 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
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 170 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 165 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
 
LVL 21

Assisted Solution

by:nizsmo
nizsmo earned 165 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

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

Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The Need In an Active Directory enviroment, the PDC emulator provide time synchronization for the domain. This is important since Active Directory uses Kerberos for authentication.  By default, if the time difference between systems is off by more …
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now