You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Operator overloading is skipped when the operand is an erased (mixed/cell) value, so BcMath\Number arithmetic computes on the pointer. #263
Known-bug repro: tests/aot/repro/crash/overloadable_erased_operand.php — bash tests/aot/xfail.sh -k overloadable_erased_operand reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.
Operator overloading (Manticore\Overloadable, BcMath\Number) is a compile-time rewrite in InlineClosures::tryOperator: an arithmetic / comparison node whose operand is statically typed as an implementing class becomes a __operator / __compare method call. An operand typed mixed / cell / unknown (an untyped parameter, an array_reduce accumulator, an element read) is not rewritten, so + emits integer arithmetic on the object pointer. Result: wrong answer or SIGBUS instead of the Zend answer.
Impact
Any generic code that passes a Number (or a user Overloadable) through an untyped slot: callbacks, array_map/array_reduce, mixed params, container elements.
Proposed approach
Runtime dispatch on the erased path, decided where the erased arithmetic is emitted (EmitLlvmExpr, the tagged add/sub/mul/div/mod and the cell compare):
In the tagged-arith slow path, when an operand's tag is OBJECT, test the class for Manticore\Overloadable (class table flag, one bit per class) and call its __operator / __compare through the vtable; otherwise keep today's TypeError (Unsupported operand types).
Fast paths (int/float) are untouched, so there is no cost for ordinary numeric code.
Reuse the swapped-operand and ** / unary-minus conventions already in tryOperator.
Acceptance
tests/aot/repro/crash/overloadable_erased_operand.php passes and is promoted to cases/.
Same result for a statically typed and an erased operand.
Non-Overloadable objects in arithmetic still raise TypeError as in Zend.
Related: local branch bcmath (operator hooks, Overloadable).
Activity
blacktrs commentedon Oct 15, 2026
Context
Operator overloading (
Manticore\Overloadable,BcMath\Number) is a compile-time rewrite inInlineClosures::tryOperator: an arithmetic / comparison node whose operand is statically typed as an implementing class becomes a__operator/__comparemethod call. An operand typedmixed/ cell / unknown (an untyped parameter, anarray_reduceaccumulator, an element read) is not rewritten, so+emits integer arithmetic on the object pointer. Result: wrong answer or SIGBUS instead of the Zend answer.Impact
Any generic code that passes a
Number(or a userOverloadable) through an untyped slot: callbacks,array_map/array_reduce,mixedparams, container elements.Proposed approach
Runtime dispatch on the erased path, decided where the erased arithmetic is emitted (
EmitLlvmExpr, the tagged add/sub/mul/div/mod and the cell compare):Manticore\Overloadable(class table flag, one bit per class) and call its__operator/__comparethrough the vtable; otherwise keep today's TypeError (Unsupported operand types).**/ unary-minus conventions already intryOperator.Acceptance
tests/aot/repro/crash/overloadable_erased_operand.phppasses and is promoted tocases/.TypeErroras in Zend.Related: local branch
bcmath(operator hooks,Overloadable).ext/bcmath, BcMath\Number, operator overloading, readonly-class fixes…
Add repro for Overloadable operators on erased operands (#263)