Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

xhp does not prefix class names with the \ prefix and therefore cannot be used within a php namespace #6

Closed
20after4 opened this issue Feb 17, 2010 · 3 comments

Comments

@20after4
Copy link

PHP 5.3 requires class namespaces to be explicit, even for classes that are in the global namespace. The XHP-generated source code does not provide a \ prefix on class names so when used within a namespace declaration the generated code fails with a fatal error, e.g.:

Fatal error: Class 'my\current\namespace\xhp_div' not found in /path/to/file ...

I think the only workaround currently would be to manually import each of the xhp classes into the current namespace and unfortunately the backslash namespace prefix would cause generated code to be incompatible with php 5.2.

@20after4
Copy link
Author

I don't quite understand how the xhp code generator works. It shouldn't be difficult to add a \ somewhere but I'm failing to find where that should be added to make xhp output the explicit global namespace reference. :(

@20after4
Copy link
Author

Ok I figured out how to implement it ... this breaks backwards compatibility with php 5.2 but that's fine for my purposes. The change is pushed to http://github.com/20after4/xhp

@laverdet
Copy link
Contributor

laverdet commented Mar 9, 2010

Thanks for the heads up on this. I added a special case for PHP 5.3 so that it will always reference the global namespace while instantiating XHP classes. Of course you'll have to be sure to not have a namespace in any file where you define XHP elements or else you'll never be able to instantiate them. Check out master and let me know if it works for you.

See: 8595cf7

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants