PHP target and its quotes

59 views
Skip to first unread message

Hitmark7

unread,
Mar 1, 2016, 11:29:59 AM3/1/16
to Haxe
An idea for improving the PHP target behaviour:

I've noted that a string defined with double quotes in Haxe, that do not allows string interpolation, translates into a string defined with double quotes in PHP, that allows it.

On PHP, the "static" strings should be defined with single quotes since that's a bit faster.

Thanks for your great work. :)

Hitmark7

unread,
Mar 1, 2016, 11:32:35 AM3/1/16
to Haxe
A little example:


class Main {

   
static public function main():Void {
       
var name = "Joan";
        trace
("Hello World");
        trace
('Hello $name');
   
}

}


Translates into:

<?php

class Main {
   
public function __construct(){}
   
static function main() {
        $name
= "Joan";
        haxe_Log
::trace("Hello World", _hx_anonymous(array("fileName" => "Main.hx", "lineNumber" => 6, "className" => "Main", "methodName" => "main")));
        haxe_Log
::trace("Hello " . _hx_string_or_null($name), _hx_anonymous(array("fileName" => "Main.hx", "lineNumber" => 7, "className" => "Main", "methodName" => "main")));
   
}
   
function __toString() { return 'Main'; }
}

Justin Donaldson

unread,
Mar 1, 2016, 8:18:27 PM3/1/16
to Haxe
You'll get a better response if you post this over on the haxe issues page:


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Hitmark7

unread,
Mar 2, 2016, 3:25:21 AM3/2/16
to Haxe
I think that the issues board it's more like a bug tracking tool. Since this is not exactly a bug, just an improveable thing, I preferred not to mess up more that board. Haxe developers who participate on this Google group and on the issues board, what do you think?

(Hehe, Justin, are you one of them? XD)

Juraj Kirchheim

unread,
Mar 2, 2016, 3:57:01 AM3/2/16
to haxe...@googlegroups.com

Hitmark7

unread,
Mar 2, 2016, 4:21:50 AM3/2/16
to Haxe
Several months ago I read a similar article, also with benchmarks, proving my premise. Sorry, I can't find it now.

I think it's easy. The parser sees double quotes and knows that it has to apply some transformations to the string. On single quotes, no transformations are needed. I'm pretty sure that the time required for such transformations is little, but on a program with thousands of code lines, like some I've worked with, it may become significant.

Either way, once the process is automated, why don't use single quotes even if the performance is just a little better? I don't know, but the logic for translating Haxe double quotes into PHP single quotes may be very simple.
Reply all
Reply to author
Forward
0 new messages