Closed AlexHaxe closed 5 years ago
<?php
set_include_path(get_include_path().PATH_SEPARATOR.__DIR__.'/lib');
spl_autoload_register(
function($class){
$file = stream_resolve_include_path(str_replace('\\', '/', $class) .'.php');
if ($file) {
include_once $file;
}
}
);
\php\Boot::__hx__init();
#(unknown)
\Main::main();
Actually, I don't think there is anything to do on the Haxe side here. Except maybe better document such situation to increase awareness.
Did you try -D php-prefix=my.pack
? It will generate all the code into \\my\\pack
namespace.
-D php-prefix=some.package
seems to solve the issue, it seems like I was unaware of that option.
I tried running with -D php-prefix=haxe
, which results in a "Class 'haxe\haxe\Std' not found" error, but other namespace names work.
So I would say that fixes my issue, and I agree that maybe some documentation warning of such a naming conflict would help. The PHP section in Haxe manual is rather short and I definitely looked at it before opening my issue.
ok, now that I've tested with an actual project, instead of sample code, I found two issues when using -D php-prefix=my.pack -php out
:
res
folder is generated in out/res
, but generated code searches for ressources in out/lib/my/res
Type.getClassName (MyType)
, but that call returns classname and package without prefixes. I guess I can call Compiler.getDefine("php-prefix")
to adjust any classname I pass on to Wordpress. Not sure if that would pose a problem somewhere else.With the latest dev Haxe there should be no issues with -D php-prefix=haxe
in Wordpress I need to register some handlers/callbacks for which I call Type.getClassName (MyType), but that call returns classname and package without prefixes. I guess I can call Compiler.getDefine("php-prefix") to adjust any classname I pass on to Wordpress. Not sure if that would pose a problem somewhere else.
Try php.Syntax.nativeClassName(MyType)
.
Thanks, that works for Haxe 4. For Haxe 3 I still have to use Compiler.getDefine
.
Haxe 3 also suffers from res
folder location issue, when using --php-prefix=my.pack
latest Resource.hx
change fixes res
location problem
Given that it's unlikely there will be next patch release of 3.4 and the issue is fixed in 4.0, I'm closing it.
Recently I wrote a Wordpress plugin in Haxe targeting PHP7. It worked fine on my local system, but not on target system. I could get it to work by switching include paths (Haxe's lib first, then system includes). Today I learned that ordering breaks media uploads, so I had to limit my plugin to only invoke when run through
index.php
.I have investigated further (I don't have direct access to target's log files) and I found a way to reproduce locally:
pear install Date
php index.php
Affects both Haxe 3 and 4, PHP5 works fine due to different loading mechanism.
I guess there is potential for more such conflicts, at least for modules in root package - not only std, but also with modules from libs or your own source code.