I'm having trouble with instantiating a class from within a script. My code basically looks like this:
ConstAttributes.php located on server at e.g. /var/www/abc/def/
<?php
namespace My\Path;
class ConstAttributes {
const ONE = "some";
const TWO = "text";
const THREE = "here";
}
?>
index.php located elsewhere on server at e.g. /var/www/xyz/123/
<?php
use My\Path\ConstAttributes;
$aInst = new My\Path\ConstAttributes();
?>
I also tried:
use My\Path\ConstAttributes;
$aInst = new ConstAttributes();
but same result. I'm testing this live on an apache2 server. apache ist configured to point on the index page. When I'm refreshing the page, it's just blank - nothing on it. Everything that comes after I create the instance just isn't displayed at all; seems like the script hung himself up there. When I do something like this:
use My\Path\ConstAttributes;
//$aInst = new My\Path\ConstAttributes();
echo 'test';
I do get the echo message as expected.
The point in doing this is accessing the const
variables in the index.php script. Before trying to instantiate the class, I tried ConstAttributes::ONE
but that's dying there like it's doing when I'm instantiating the class.
I've googled quite alot now but couldn't solve the problem. Help would be much appreciated.
Thanks in advance.