theseer / Autoload

A lightweight php namespace aware autoload generator and phar archive builder
Other
388 stars 47 forks source link

namespace declaration with leading "\" #8

Closed Flyingmana closed 13 years ago

Flyingmana commented 13 years ago

phpap cant handle namespaces which are declared the following way

namespace \test\me;

theseer commented 13 years ago

The declaration is wrong. While obviously PHP does not complain about that syntax when doing a lint, the leading \ is bogus and not valid php code. I'm not convinced that is something phpab should handle. I could of course add an exception to bail out but since the file doesn't load, it's not going to work either way on production.

Flyingmana commented 13 years ago

what is about throwing an error for a "malformed" namespace?

theseer commented 13 years ago

I could add that of course but I actually consider that a PHP Parser bug for that definition doesn't make any sense and should fail at parse time. If you try to run code that has that type of definition, you get a fatal error for an undefined constant. This is beyond phpab's job to validate - let alone fix. But I'll consider opening a PHP bug on it.

theseer commented 13 years ago

As broken as it may be, the syntax is valid - though not to define a namespace: http://docs.php.net/manual/en/language.namespaces.nsconstants.php

I'll check whether or not I have to deal with this in any way within phpab.

Flyingmana commented 13 years ago

thx for your effort about this

theseer commented 13 years ago

Commit 112339f0c48be96b8d14 fixes the issues triggered by the inline use of the namespace keyword. Again, using namespace \a\b; does not define a namespace a\b but accesses a constant a\b within the current namespace.

phpab will be able to parse this properly coming the next release.