PHP Free Tutorial

Function Libraries in PHP

In PHP, Programming by Baqir Ali

We can make a separate PHP file of our commonly used user-defined function and treat them as libraries. PHP provides two common constructs for including files in web pages: require and include. They are basically the same with one minor difference. require throws a fatal error when it fails; whereas, include only gives a warning. If you need the included file to continue to process the page, you should use require. It is important to keep in mind that a PHP tag cannot start in a calling file and continue in an included file. All PHP code in the included file must be nested in PHP tags.

Require in PHP

Require is not actually a function, but a  language construct, so require statements can be written in two ways:

require path_to_file;

Require_Once in PHP

Require_once can be used just like require. The difference is that if the included file has already been included by earlier code, it will not be re-included.

Support us by sharing this post