Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php codegen when using double byte chatecters in object string #11911

Open
neimanpinchas opened this issue Jan 6, 2025 · 0 comments
Open

php codegen when using double byte chatecters in object string #11911

neimanpinchas opened this issue Jan 6, 2025 · 0 comments

Comments

@neimanpinchas
Copy link

I am using this haxe code

function main() {
    Sys.println("אבגדהו");
    var list={
        "אבגדהו":"abcd",
        "אבדהו":"abcd",
    }
    trace(list);
}

In the first print, the Hebrew characters are copied directly to the resulting php file.

However for the object keys, they are trying to get escaped, but the algorithm is not good.
א
in utf8 is D7 90

this is 215 144 in decimal

PHP would interpret backslash escape as octal, but the Haxe generator inserts the decimal values instead.

The result is that the characters render as gibberish.

It would need any of the follwing

  1. leave the original text (php supports inline utf8)
  2. use octal values
  3. escape with haxedecimal escaping

I tried to navigate the php7 gen file, but was unsuccesfull in finding the cause.

In control charecters less then ASCII 32, the generator is using haxedecimal escaping such as \x0A which is good.

generates the follwing php

<?php
/**
 * Generated by Haxe 4.3.4
 */

namespace _TestPhp;

use \php\_Boot\HxAnon;
use \php\Boot;
use \haxe\Log;

final class TestPhp_Fields_ {
	/**
	 * @return void
	 */
	public static function main () {
		#TestPhp.hx:2: characters 5-26
		echo("אבגדהו" . \PHP_EOL);
		#TestPhp.hx:3: lines 3-6
		$list = new HxAnon([
			"\215\144\215\145\215\146\215\147\215\148\215\149" => "abcd",
			"\215\144\215\145\215\147\215\148\215\149" => "abcd",
		]);
		#TestPhp.hx:7: characters 5-10
		(Log::$trace)($list, new HxAnon([
			"fileName" => "TestPhp.hx",
			"lineNumber" => 7,
			"className" => "_TestPhp.TestPhp_Fields_",
			"methodName" => "main",
		]));
	}
}

Boot::registerClass(TestPhp_Fields_::class, '_TestPhp.TestPhp_Fields_');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant