Req #73374 [Opn]: intval() with base 0 should detect binary

From: Date: Tue, 25 Oct 2016 15:00:34 +0000
Subject: Req #73374 [Opn]: intval() with base 0 should detect binary
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204997@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73374&edit=1 ID: 73374 Updated by: cmb@php.net Reported by: nikic@php.net -Summary: intval() with base 0 does not detect binary +Summary: intval() with base 0 should detect binary Status: Open Type: Feature/Change Request Package: Math related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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] <http://php.net/manual/en/function.intval.php> Previous Comments: ------------------------------------------------------------------------ [2016-10-22 23:00:27] ajf@php.net 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-22 21:58:06] nikic@php.net Description: ------------ 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. https://3v4l.org/GYVQa Test script: --------------- var_dump(intval('0b1101', 0)); Expected result: ---------------- int(13) Actual result: -------------- int(0) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73374&edit=1

« previous php.bugs (#204997) next »