Unstoppable Domains

Quick question, to a new Php programmer

Spaceship Spaceship
Watch

.jd.

Established Member
Impact
11
Does a PHP script contain more the one php file? I am a little confused on this. Is the script just one big script with everything inside of it? Or is it many PHP files that do different things to make it all work.

All help is appreciated, Thank you

~ prodigy
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Not sure if I understand your question, but I'll give it a try.

A PHP-script can be built using a single file or several files. In a PHP-file you can include other PHP-files (or for example HTML-files).

Something that I do (and many others too) is that I have several functions that I have made and that I often need to use over and over again. Such functions I often place in a separate PHP-file and include them whenever I need them (if you don't know about including http://no2.php.net/include/).

Point is; you can place all of your PHP-code in a single file or you can separate it in to several files, all depending on how you like it and what the website you're working on demands.
 
0
•••
Wuoshi said:
Not sure if I understand your question, but I'll give it a try.

A PHP-script can be built using a single file or several files. In a PHP-file you can include other PHP-files (or for example HTML-files).

Something that I do (and many others too) is that I have several functions that I have made and that I often need to use over and over again. Such functions I often place in a separate PHP-file and include them whenever I need them (if you don't know about including http://no2.php.net/include/).

Point is; you can place all of your PHP-code in a single file or you can separate it in to several files, all depending on how you like it and what the website you're working on demands.
require is often faster http://ee2.php.net/require
 
0
•••
0
•••
ok, so having different files to do different task. Using the require () function is better then having one big php script in one file? Correct me if I am wrong.
 
0
•••
If you're going to have certain functions or code that will be needed by other files, such as already given... a 'functions' file, then yes, you should use several files.

If you want, download www.domainportfolio.us , and take a look through it's files ;)
 
0
•••
hanz said:


Anything that backs that up, all the PHP manual states is that include() and require() are identical in every way except for possible errors thrown on failure.

Some people do create an entire script within 1 file but this can fast become unmanageable. Splitting sections up according to what the do is a much more logical way of doing it for example having functions in a separate file or every class in a separate folder.

Splitting up like this make things much easier to manage as stated and also aids in re-usability.

k1dprodigy said:
ok, so having different files to do different task. Using the require () function is better then having one big php script in one file? Correct me if I am wrong.

require and require_once should be used (as the name suggests) when a file HAS to be used in the script. include and include_once should be used when a script should be able to continue regardless of whether the script was successfully included.
 
0
•••
peter@flexiwebhost said:
Anything that backs that up, all the PHP manual states is that include() and require() are identical in every way except for possible errors thrown on failure.

Some people do create an entire script within 1 file but this can fast become unmanageable. Splitting sections up according to what the do is a much more logical way of doing it for example having functions in a separate file or every class in a separate folder.

Splitting up like this make things much easier to manage as stated and also aids in re-usability.



require and require_once should be used (as the name suggests) when a file HAS to be used in the script. include and include_once should be used when a script should be able to continue regardless of whether the script was successfully included.

Thank you, this is the answer I was seeking.
 
0
•••
SecondVersion said:
If you're going to have certain functions or code that will be needed by other files, such as already given... a 'functions' file, then yes, you should use several files.

If you want, download www.domainportfolio.us , and take a look through it's files ;)

Yep. A global functions file can be insanely useful. I can just add a <?php require_once(“/home/danltn/functions”); ?> on the top of a page to include my entire functions list.
 
0
•••
Where can I find these global functions? Like a list of them
 
0
•••
they mean that they have say a file called functions.php. In this file they will have created their own functions and placed them in this file. By requireing/including the functions php at the top of a script (or in a script that will be included by all scripts in the package) the functions are then available script wide (everywhere).

For example say I have my database details in config.php. I could do require_once('functions.php') within the config.php script. Now any script that has included the config.php script also has access to all the functions.
 
0
•••
k1dprodigy said:
Where can I find these global functions? Like a list of them

A good source of functions is yourself. PHP.net sometimes has good functions to work around errors that PHP has.

Dan
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back