Skip to content

Fix bInt() turning negative numbers into huge positive ones - #11

Merged
ellisgl merged 1 commit into
releasefrom
fix-bint-negative
Nov 25, 2026
Merged

ellisgl merged 1 commit into
releasefrom
fix-bint-negative

Conversation

@ellisgl

@ellisgl ellisgl commented Nov 25, 2026

Copy link
Copy Markdown
Owner

bInt() formatted its value with sprintf('%u', …), which reads it as unsigned. Every negative number came out wrong:

Input Before After
-5 9223372036854775807 -5
'-5' 9223372036854775807 -5
-1.9 9223372036854775807 -1
1.9, '2.5', '1e3' 1, 2, 1000 unchanged
'9223372036854775808' (too big) 9223372036854775807 (silently clamped) InvalidArgumentException
1e20, INF, NAN silently wrong InvalidArgumentException

Positive values and float truncation behave as before. The %u format dates from the initial commit, and no test covered negative numbers.

Tests: new tests/MySQLNumericBindingsTest.php (18 cases, no database needed). The full suite passes against MySQL 8.4 (68 tests), along with PHPStan level 8 and PSR-12.

🤖 Generated with Claude Code

bInt() formatted values with sprintf('%u'), which treats them as
unsigned: bInt(-5) bound 9223372036854775807. It now keeps the sign,
truncates floats toward zero as before, and throws
InvalidArgumentException for values outside the integer range
(including INF and NAN) instead of binding a wrong number.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ellisgl
ellisgl merged commit f44ca26 into release Nov 25, 2026
7 checks passed
@ellisgl
ellisgl deleted the fix-bint-negative branch November 25, 2026 14:48
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

Successfully merging this pull request may close these issues.

1 participant