|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73374 intval() with base 0 should detect binary
Submitted: 2016-10-22 21:58 UTC Modified: 2016-10-31 17:41 UTC
From: Assigned:
Status: Closed Package: Math related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2016-10-22 21:58 UTC]
intval() using base 0 currently detects decimal, octal and hexadecimal numbers based on notation. However, binary numbers are always converted to 0. As PHP supports binary number literals as of PHP 5.4 they should be supported here as well.

Test script:
var_dump(intval('0b1101', 0));

Expected result:

Actual result:


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-22 23:00 UTC]
-Type: Bug +Type: Feature/Change Request
 [2016-10-22 23:00 UTC]
I'm recategorising this as a feature request, because intval() isn't inherently tied to PHP's integer literal formats, much as one might wish it were.
 [2016-10-25 15:00 UTC]
-Summary: intval() with base 0 does not detect binary +Summary: intval() with base 0 should detect binary
 [2016-10-25 15:00 UTC]
Also, the behavior is documented as such[1]:

| If base is 0, the base used is determined by the format of var:
| * if string includes a "0x" (or "0X") prefix, the base is taken as 16 (hex); otherwise,
| * if string starts with "0", the base is taken as 8 (octal); otherwise,
| * the base is taken as 10 (decimal).

[1] <>
 [2016-10-31 17:41 UTC]
Added a PR for this, feels clunky to me but not sure how to avoid it, what do you think?
 [2017-01-12 17:54 UTC]
Automatic comment on behalf of leigh
Log: Fixed bug #73374
 [2017-01-12 17:54 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 14:01:29 2024 UTC