SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,207
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    parenthesis in INCLUDE

    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?

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    The parenthesis are just an optional syntax.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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 Code:
    <?php

    $var 
    "<p>Eeek, a mouse!</p>";
    file2.php
    PHP Code:
    <?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.

  4. #4
    SitePoint Guru bronze trophy
    Join Date
    Dec 2003
    Location
    Poland
    Posts
    925
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dotJoon View Post
    I like to learn about the function of parenthesis in INCLUDE.

    What is the function of it?
    They have no function in include. In php you are required to use parentheses after functions, for example:
    PHP Code:
    $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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •