Notice: Undefined variable: var2 in C:\xampp\php\testscript.php on line 9 PHP Notice: Undefined variable: var2 in C:\xampp\php\testscript.php on line 9 This will produce following result when main script is run from command line− 100 Hence variables in the include file will not accessible outside the function Example Code inside included file will be treated as part of function. In next example, test.php is included inside a function. Returns from nosuchfile.php include from inside function PHP Warning: include(): Failed opening 'nosuchfile.php' for inclusion (include_path='C:\xampp\php\PEAR') in line 5 PHP Warning: include(nosuchfile.php): failed to open stream: No such file or directory in line 5 Note that program doesn't teerminate on warning − inside main script In following example,attempt to include nonexisting file results in warning Example This will produce following result when main script is run from command line − inside main scriptnow calling test.php script300returns from test.php Warning for failed include In following example main php script includes test.php Example The included file can access variables defined in calling module prior to inclusion. If file asked for is not available in current folder as well as include_path folders, PHP parser emits E_WARNING and execution of calling module continues. The include statement checks for the file in current folder by default and further in directories mentioned in include_path setting of php.ini. This feature enables modular program development by writing functions and classes once and calling wherever needed. PHP code in one file can be made available for use in another PHP script with the help of include statement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |