Benjamin fox
Benjamin fox

Reputation: 95

Diffrence Between Include And Include()

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

Answers (5)

Rahul Desai
Rahul Desai

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

Morgan Touverey Quilling
Morgan Touverey Quilling

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

Branimir Đurek
Branimir Đurek

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

devajay
devajay

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

Cl&#233;ment Andraud
Cl&#233;ment Andraud

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

Related Questions