Parenthesis in INCLUDE

[b]code1[/b]
"myPath/included.php"; 

[b]cod2[/b]
include [COLOR="#FF0000"]([/COLOR]"myPath/included.php"[COLOR="#FF0000"])[/COLOR];

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.

What is the function of it?

Put 2 files in the same top level directory, name the directory /inc_test

inc_test

file1.php


<?php

$var = "<p>Eeek, a mouse!</p>";


file2.php


<?php

echo "<p>What's that noise?</p>";

include './file1.php';

echo $var;

The load up in your browser…

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:


$str = trim(" some string");

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.

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.