I just found out a very strange PHP feature by browsing the PHP-GTK2 API with the Reflection classes : spaces can be used in some alien places, like variable names.
But the doc says you can't !
Well, try this in PHP 5.2.5, for instance:
Spaces in PHP variable names
Spaces in PHP constant names
The case with constants is better known, being mentioned on php.net :
Spaces in other PHP names
Stranger is the fact that you are not allowed to use that same syntax on parameter names, class constants, or class properties: in every case, the syntax fails.
Spaces in PHP-GTK names
So how does this related to PHP-GTK2 ? Actually, I discovered this possibility about spaces in variable names because the Reflection API shows GdkColorMap::alloc_color()
like this:
There's a bit of magic in ext/gtk+/gdk.overrides regarding these parameters (starting line 312 in version 1.81), because this is not the default Gdk format.
However, at any rate, it seems that this syntax is not allowable from PHP source, even though the PHP-GTK extension uses it.
Restricting dynamically named variables is useless
Well, the docs only mentions naming rules for "explicit" variable names. This restriction is enforced by the lexer. But dynamically, there is no point into restricting such names,just like you can define every exotic constants, but only access them back through
constant()
.Consistency
Why only on variables
The reason why its allowed on variables is because of the way object parameters and array keys intermingle - Imagine having an array
and then doing
You will then have to use
$o->{'some name'}
to get at that value.You can also then access the other object like
$o->{'some name2'}->someotherobjectparameter;