Including Code From Other Files
The require construct seen in the example above—in a nutshell—imports the
contents of an external PHP file into our DogTest.php file. It's one of four such
constructs used to include code from other files, each with slightly different behavior:
■ include ― includes the contents of the file. If the file isn't found or is inaccessible,
PHP will issue a warning but will continue executing.
■ include_once ― the same as include, but PHP performs an extra check to
make sure the file hasn't been imported already. If it has, then PHP will not
re-include the contents.
■ require ― similar to include but PHP will stop execution with a fatal error
if the file isn't found.
■ require_once ― the same as require but with an extra check to ensure the
content isn't imported more than once.
Taking
The require construct seen in the example above—in a nutshell—imports the
contents of an external PHP file into our DogTest.php file. It's one of four such
constructs used to include code from other files, each with slightly different behavior:
■ include ― includes the contents of the file. If the file isn't found or is inaccessible,
PHP will issue a warning but will continue executing.
■ include_once ― the same as include, but PHP performs an extra check to
make sure the file hasn't been imported already. If it has, then PHP will not
re-include the contents.
■ require ― similar to include but PHP will stop execution with a fatal error
if the file isn't found.
■ require_once ― the same as require but with an extra check to ensure the
content isn't imported more than once.
Taking
No comments:
Post a Comment