Php target : namespace

83 views
Skip to first unread message

Lionel Salabartan

unread,
Mar 21, 2016, 9:49:00 AM3/21/16
to Haxe
Hi all,

I wonder if the PHP target going to be improved to use namespaces or if the option I'm searching already exists.

Let me explain. Currently, the PHP target seems to generate a bootloader and change the classname accordingly to the package tree.
package foo.bar;

class Toto {}

generate in the directory foo\bar the file Toto.class.php
class foo_bar_Toto {}

I understand that choice for php 5.1 but with the arrival of namespaces in PHP 5.3 and the large adoption of Composer with an integrated autoloader.
I think it is not worth to generate this code except of course to be compatible with 5.1. (adding a flag to keep the two possibility surely).

For 5.3, it can be generate like this in the directory Foo\Bar in the file Toto.php:
namespace Foo\Bar;

class Toto {
}
and like this with standard Haxe library :
namespace Haxe;

class Log {
}

So I wonder if it is necessary to modify the code of haxe for this generation or so to get to do that via macros.
I have not much experience in haxe, sorry if I missed something or if this improvement is not relevant.

Lionel

Lionel Salabartan

unread,
Mar 21, 2016, 9:58:48 AM3/21/16
to Haxe
I forgot to say that Closure had added to 5.3 and can be use too.

Andreas Mokros

unread,
Mar 22, 2016, 8:03:23 AM3/22/16
to haxe...@googlegroups.com
Hi.

On Mon, 21 Mar 2016 06:48:59 -0700 (PDT)
Lionel Salabartan <lionel.s...@gmail.com> wrote:
> I wonder if the PHP target going to be improved to use namespaces
> For 5.3, it can be generate like this in the directory Foo\Bar

This is well-known already.

> So I wonder if it is necessary to modify the code of haxe for this
> generation

Yes. This would have to be done in the generator (written in OCaml).

> sorry if I missed something or if this
> improvement is not relevant.

No problem. It surely would be nice to have (besides of lots of other maybe more
important improvements), but the PHP target has no real maintainer at the
moment. Also the codebase is quite old and difficult to modify without breaking
something.

> I forgot to say that Closure had added to 5.3 and can be use too.

Yes, this is a more important one IMO. Otherwise see above.

--
Mockey

Lionel Salabartan

unread,
Mar 23, 2016, 6:45:51 AM3/23/16
to Haxe
Thank you for the response, Andreas !

Maybe, I will try to fix this, but my learning of Ocaml is quite old and small...

Nicolas Juneau

unread,
Mar 23, 2016, 8:59:27 PM3/23/16
to haxe...@googlegroups.com
The PHP target has no real maintainer? That's a shame - it's a target I
really enjoy and I would sure like it to evolve. Namespaces would
definitely be a nice thing. I'm no OCaml expert, unfortunately :(
Reply all
Reply to author
Forward
0 new messages