Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

/ binop throws DivisionByZeroError on PHP8 target (Dynamic division by zero)

Open Beginner friendly
#166 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Domain
compilers

Research direction

Start in Interp.hx, specifically initOps() and the default "/" binop, then run the provided Parser and Interp reproduction with PHP 8 and another target. Compare the division-by-zero result with Haxe's documented Float behavior; done means the expression no longer throws on PHP 8 and remains consistent across targets.

Written by the indexing model from the issue text.

Description

I think this should be reported on Haxe github but since I guess that the answer will be to avoid using Dynamic I try to post it here because hscript is by default using Dynamic.

On the PHP target, Interp's default / binop (Interp.hx, initOps()):

binops.set("/", function(e1,e2) return me.expr(e1) / me.expr(e2));
relies on the native / operator on Dynamic operands. Since PHP 8.0, / throws DivisionByZeroError for any division by zero (including Float), whereas other targets (JS, etc.) return Infinity/NaN without throwing — per Haxe's own documented Float/IEEE754 semantics. Since Interp.expr() always operates in Dynamic, this cross-target guarantee silently breaks specifically on PHP8, even when both operands are genuinely Float at runtime.

Repro:

var i = new hscript.Interp();
i.variables.set("x", 1.0);
i.variables.set("y", 0.0);
i.execute(new hscript.Parser().parseString("x / y")); // throws on PHP8, returns Infinity on JS

Suggested fix guard the divisor explicitly instead of relying on the native operator, restoring cross-target consistency:

binops.set("/", function(e1,e2){
    var b = me.expr(e2);
    return b == 0 ? Math.NaN : me.expr(e1) / b;
});
Dominant language
Haxe
Stars
309
Forks
154
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from HaxeFoundation/hscript

All issues in HaxeFoundation/hscript

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.