Solved

PHP Require_Once

Posted on 2007-12-06
9
249 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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
 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
Resolve DNS query failed errors for Exchange
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

770 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