PHP Require_Once

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
mhoggatt1Asked:
Who is Participating?
 
steelseth12Connect With a Mentor Commented:
>> 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
 
wildzeroConnect With a Mentor Commented:
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
 
wildzeroCommented:
well done :-)
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
nizsmoConnect With a Mentor DeveloperCommented:
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
 
mhoggatt1Author Commented:
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
 
wildzeroCommented:
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
 
nizsmoDeveloperCommented:
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
 
steelseth12Commented:
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
 
mhoggatt1Author Commented:
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
All Courses

From novice to tech pro — start learning today.