Amazing facts about namespacing in PHP
Heinz Wiesinger
HMWiesinger at liwjatan.at
Wed Nov 25 12:07:32 UTC 2015
On Tuesday 24 November 2015 15:56:03 Alexander Zhigalin wrote:
> BUGHUNT MODE ON;
>
> {0-noname.png}
> There is a lazy class load system, so no includes, \Application\DB is used 3
> times.
> \Application\DB is not recognized(as every other classes in other
> namespaces, as was stated here: https://bugs.kde.org/show_bug.cgi?id=280985
> (btw, 3 year with no fix...)), Application\DB is recognized but wrong.
> I have made a supposion that the parser doesn't recognize the leading
> backslash, but...
>
> {1-require.png}
> If we directly include the file /Application/DB.php the thing work.
> Obliviously, including tons of files just to get duchain working is not an
> option.
>
> we_need_to_go_deeper.jpg :)
>
> {2-nobackslash.png}
> WTF? What kind of logic make it working then we leave just 1 backslash of 3?
>
> Another two things:
>
> 1: Somewhere in duchain all the namespace names are being lowercased, while
> is PHP namespaces aren't always lowercase, moreover they're case-sensitive
> and "\Application" != "\application". I lurked inside the sources but I had
> no success. Maybe someone will be able to suggest where is that mysteriuos
> place?
>
> 2: Sometimes in the completion the same namespace appears more times...
The bug you're describing here is actually pretty complex and has to do with
how we look up namespaced classes in the persistant symbol table. The problem
is that \namespace\class means something different than namespace\class (note
the missing backslash in the beginning), and doing all the possible
permutations is not easy, especially with conceptual namespace differences in
PHP and C++ semantics.
You should be able to work around this issue by importing the class. I.e.
write something like "use \Application\DB;" on top of the file, below the
namespace declaration. (This BTW, will only work in 1.7.x. Earlier versions
don't have support for use aliases).
Grs,
Heinz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 213 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20151125/b7e195b6/attachment.sig>
More information about the KDevelop-devel
mailing list