SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist Fergal's Avatar
    Join Date
    Nov 2003
    Location
    Ireland
    Posts
    500
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Why does include use quotes instead of brackets?

    A statement to include a file looks like this:

    PHP Code:
    include 'file_to_include.php'
    Why is it not like this?

    PHP Code:
    include(file_to_include.php); 
    Thanks!
    Fergal Crawley (Previous Username: Proudirish.com)
    Business Advice Forum - Webmaster and Business Forum
    < Get a free link & win $5,000
    Forum Coin New World Currency

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,192
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    You mean "parentheses"

    Any way, parentheses are used for functions. include (and a few other things) are -not- functions, as you yourself said, they're "statements".

    So you don't need to use the parenthess. Many do use them, which adds to the misconception many have. But that's the lowdown.

  3. #3
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,196
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    An include is a language construct, which is why the parentheses is optional.

    On a side note, when you include a file without a full path name, add ./ in front of the name, to avoid PHP first checking any include folders setup in the ini file.

    Example:
    PHP Code:
    include './file_to_include.php'
    include(
    './file_to_include.php'); 
    You can check out the other language constructs PHP has here:
    http://www.php.net/manual/en/reserved.keywords.php

    Quote Originally Posted by Mittineague View Post
    You mean "parentheses"
    Yes, he said so in the title Joke aside, he is from Ireland and they normally say brackets and not parentheses there (UK, Australia and perhaps other countries as well).

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,192
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    Thanks for the much better explanation @TheRedDevil ;

    I can overlook the brackets vs. parentheses thing seeing as I should have said language construct but said statement

  5. #5
    SitePoint Evangelist Fergal's Avatar
    Join Date
    Nov 2003
    Location
    Ireland
    Posts
    500
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mittineague and TheRedDevil for the helpful explanations and links.

    Quote Originally Posted by TheRedDevil View Post
    ...he is from Ireland and they normally say brackets and not parentheses...
    Yes we do, sorry for the confusion
    Fergal Crawley (Previous Username: Proudirish.com)
    Business Advice Forum - Webmaster and Business Forum
    < Get a free link & win $5,000
    Forum Coin New World Currency


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
  •