CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2006
    Posts
    306

    PHP Namespace Error

    I keep getting an error. Here is some code.
    Code:
    <?php // PSystem.php
    namespace PSystem;
    ?>
    Yeah, that's all.

    Code:
    <?php // tester.php
    include 'PSystem.php';
    echo "Works";
    ?>
    I keep getting this error.
    Code:
    PHP Parse error:  syntax error, unexpected T_STRING in C:\\Server\\Main\\Includes\\PSystem.php on line 2
    Is this how you are supposed to be loading namespaces, or is this just some weird error?

  2. #2
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: PHP Namespace Error

    Try this for PSystem.php
    PHP Code:
    <?php
    namespace PSystem {
      const 
    1;
    }
    ?>
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

  3. #3
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP Namespace Error

    Are you sure there isn't an accidental white-space before the PHP declaration? Remember that namespaces must be declared before output within a script.

    Also...Have you tried it with actual content in the namespace?

    @javajawa You are declaring your namespace as you would a class.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  4. #4
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: PHP Namespace Error

    Newer versions of PHP allow for that form of namespace declaration. It's useful for keeping track of where you want namespaces to end (so you can remember to re-open the global namespace, something I always forget otherwise) PHP Manual Entry
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

  5. #5
    Join Date
    May 2006
    Posts
    306

    Re: PHP Namespace Error

    Ah, yes peej. I can write
    Code:
    namespace [name]
    {
    
    }
    But, what about...
    Code:
    namespace [name] \ [subspace] \ [subspace]
    {
    
    }
    I don't think that will work, hmm well I gotta try.

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP Namespace Error

    You learn something new every day! I haven't worked with namespaces much. Useful little thing to know.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    May 2006
    Posts
    306

    Re: PHP Namespace Error

    Nope, nothing seems to work.

    Does that mean I can't use namespaces, at all? lame.

    How would I display my php info? I know there was a function and it would list everything in a complete page.

    Oh, wait a second.

    It says in phpinfo().

    Powered By PHP/5.2.5.

    Would that be of any significance?
    Last edited by code?; January 13th, 2009 at 06:25 AM.

  8. #8
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: PHP Namespace Error

    Namespaces are available in PHP as of PHP 5.3.0.
    [Source: PHP Manual]
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured