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

From: Date: Thu, 12 Jan 2017 17:54:20 +0000
Subject: Req #73374 [Opn->Csd]: intval() with base 0 should detect binary
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206572@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: nikic@php.net Reported by: nikic@php.net Summary: intval() with base 0 should detect binary -Status: Open +Status: Closed Type: Feature/Change Request Package: Math related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Automatic comment on behalf of leigh Revision: http://git.php.net/?p=php-src.git;a=commit;h=4f7b498d12b04ae25ae59a711e76410e77455a94 Log: Fixed bug #73374 Previous Comments: ------------------------------------------------------------------------ [2016-10-31 17:41:23] leigh@php.net Added a PR for this, feels clunky to me but not sure how to avoid it, what do you think? ------------------------------------------------------------------------ [2016-10-25 15:00:33] cmb@php.net 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> ------------------------------------------------------------------------ [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 (#206572) next »