php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #7878 intval base argument useless unless first arg is a string
Submitted: 2000-11-19 00:55 UTC Modified: 2001-06-23 13:26 UTC
From: zak@php.net Assigned: zak (profile)
Status: Closed Package: Documentation problem
PHP Version: 4.0.3pl1 OS: Win32 and Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: zak@php.net
New email:
PHP Version: OS:

 

 [2000-11-19 00:55 UTC] zak@php.net
The base argument for intval has no effect unless the first argument is a string.

I am not sure what the best fix for this is:

We could document that you should make the first argument a string to have the base argument used.

We could convert the first argument to a string (using  convert_to_string_ex) if there is a second argument

That would mke calls made with base 10 would work as expected:
intval (1000, 11); // Returns 1331
intval ('1000', 11); // Returns 1331

However, calls using other bases might seem a bit odd:
intval ('077', 8); // returns 63
intval (077, 8); // returns 51

This would be because 077 is converted to 63, then the argument is converted to a string.

Or we could add a warning if the first arg is not a string?

Any thoughts??


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-06 11:31 UTC] derick@php.net
I guess no-one had thoughts about this. What are we going to do with this one?
 [2001-05-06 20:44 UTC] zak@php.net
In hindsight, I think that the current behavior is fine and makes sense given how PHP currently behaves.

People just need to remember that writing a number out in a different base is for their convenience - PHP sees it as its decimal equivalent and behaves appropriately.

I have assigned it to myself so that it will bug me til I get around to documenting the behavior.
 [2001-06-01 16:02 UTC] sniper@php.net
assigned then..

 [2001-06-23 13:26 UTC] zak@php.net
Finally got around to documenting this. :)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 16:01:26 2025 UTC