Reputation: 95
I heard there is a different between include vs include() ! is that true ?
for example
include "simple.php";
is different with ->
include("simple.php");
i asked for this from someone and he told me include() is calling include function but include without () is faster and is php In-Built !
i winder he is right or not !
is include "" faster than include("") ? i tried to search in Google and PHP references but i didn't find anything
Thanks.
Upvotes: 1
Views: 113
Reputation: 15501
Include is a special language construct, parentheses are not needed around its argument.
Source: http://php.net/manual/en/function.include.php
If you do:
if (include('vars.php') == 'OK') {
echo 'OK';
}
this wont work, because it is evaluated as include(('vars.php') == 'OK')
, i.e. include('')
My advice: Stick to include example.php
. Keep it simple :)
Upvotes: 1
Reputation: 4333
They are both the same, include
is a language construct with two different syntaxes.
You have the same behaviour with echo
, exit
, etc.
Upvotes: 0
Reputation: 632
I think that include "" is just alias of include("") function. It makes code only a little bit shorter and easier to write. Basically, if there is difference between those two, it should be minimal.
Upvotes: 1
Reputation: 417
Basically include ' ' is the main function of php to add the file but when you try to enter any file as like as like this form
<?php
$root = $_SERVER['SERVER_NAME'] . '/mysite';
$theme = $root . '/includes/php/common.php';
echo $theme;
include($theme);
?>
then you need to used include function and also this is same logic in c language which you see at how to include another php file?
Upvotes: 0
Reputation: 9269
Because include is a special language construct, parentheses are not needed around its argument.
Just care when you compare return value :
<?php
// won't work, evaluated as include(('vars.php') == 'OK'), i.e. include('')
if (include('vars.php') == 'OK') {
echo 'OK';
}
// works
if ((include 'vars.php') == 'OK') {
echo 'OK';
}
?>
Upvotes: 1