I've never really worked with PHP namespacing before and I was reading up on how to use it on the PHP website, including how to include namespace code and non-nonspace (global code) in the one file.
Source: http://www.php.net/manual/en/language.namespaces.definitionmultiple.php
I then tried the below for testing:
namespace { $bar = 123; } namespace moo { $bar = 400; } namespace { echo $bar . "<br>\n"; //echo moo\$bar . "<br>\n"; } However what I got back was unexpected..
The output of the above is:
400 Shouldn't it be 123 since I am not referencing the moo namespace? Additionally, if I uncomment the next line I get a PHP syntax error.
What am I doing wrong?
{}after namespaces is new to me, I thought it was just a command at the beginning of a PHP file and I think there is something in the documentation that says variables are always global:php.net/manual/en/language.namespaces.definition.php