Code:code1 "myPath/included.php"; cod2 include ("myPath/included.php");
I like to learn about the function of parenthesis in INCLUDE.
What is the function of it?
When to use the parenthesis in INCLUDE?
| SitePoint Sponsor |





Code:code1 "myPath/included.php"; cod2 include ("myPath/included.php");
I like to learn about the function of parenthesis in INCLUDE.
What is the function of it?
When to use the parenthesis in INCLUDE?
The parenthesis are just an optional syntax.

Put 2 files in the same top level directory, name the directory /inc_testWhat is the function of it?
inc_test
file1.php
file2.phpPHP Code:<?php
$var = "<p>Eeek, a mouse!</p>";
The load up in your browser...PHP Code:<?php
echo "<p>What's that noise?</p>";
include './file1.php';
echo $var;
http://localhost/inc_test/file2.php
Should work ...
Yeah, I dropped the brackets around include calls too.
They have no function in include. In php you are required to use parentheses after functions, for example:
because trim is a function. However, include is not a function, it's a language construct. Language constructs don't require parenthesis. PHP documentation says which are language constructs, there are not many of them - some examples: include, require, echo, print. There is a subtle difference between a function and a language construct, in most cases you don't have to worry about it but for example you cannot use is_callable(), call_user_func() for language constructs, since they will not work.PHP Code:$str = trim(" some string");
You are allowed to use parenthesis in include not because include allows it itself but because you can use parentheses around any string or number in php for grouping. So for example, "dog" is equivalent to ("dog"), ("dog")."dog" is equivalent to "dog"."dog", etc. Parenthesis become useful when you use complex expressions involving calculations and string concatenations but in such a simple case they are simply allowed and perform an unnecessary and harmless "grouping" of a single string value.
Bookmarks