[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

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
0
mhoggatt1
Asked:
mhoggatt1
  • 3
  • 2
  • 2
  • +1
3 Solutions
 
steelseth12Commented:
>> 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
 
wildzeroCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
nizsmoDeveloperCommented:
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now