-
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?
-
Re: PHP Namespace Error
Try this for PSystem.php
PHP Code:
<?php
namespace PSystem {
const a = 1;
}
?>
-
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.
-
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
-
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.
-
Re: PHP Namespace Error
You learn something new every day! I haven't worked with namespaces much. Useful little thing to know.
-
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?
-
Re: PHP Namespace Error
Namespaces are available in PHP as of PHP 5.3.0.
[Source: PHP Manual]