php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #26314 Decimal numbers starting with 0 always treated as octals, even when invalid
Submitted: 2003-11-19 06:37 UTC Modified: 2004-07-26 13:05 UTC
From: matteo at beccati dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.4 OS: Debian GNU/Linux 3.0
Private report: No CVE-ID: None
 [2003-11-19 06:37 UTC] matteo at beccati dot com
Description:
------------
According to the manual, integers can be specified in the octal notation preceding the number with a zero. Some lines below I can see this regexp:

octal       : 0[0-7]+


What I don't understand is why an invalid octal number preceded by a 0 is treated as an octal, having a value of 0.

I know that you'll probably answer that it's a feature and not a bug, but I think that this behaviour should be highlighted in the manual :)

Also checked on PHP 4.1.2, 4.3.0 and 4.3.3

Reproduce code:
---------------
<?php
var_dump(07); // Correct
var_dump(010); // Correct

var_dump(08); // Wrong, 8 is not an octal number
?>



Expected result:
----------------
int(7)
int(8)
int(8)


Actual result:
--------------
int(7)
int(8)
int(0)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-19 06:39 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is exactly as it should be. If you prefix the 0 on a non-octal number, PHP still treats it as an octal number as is described in the manual. 
 [2003-11-19 06:40 UTC] matteo at beccati dot com
Fixed summary...
 [2003-11-19 06:48 UTC] derick@php.net
Fixed status
 [2003-11-19 06:50 UTC] matteo at beccati dot com
[Changed category to "Documentation problem"]

OK, I understand...

Can I suggest adding a warning in the manual to let people know what happens when the provided number is invalid? IMHO that isn't much clear now.

P.S.
Sorry for reopening it by changing the summary... I didn't know you already answered :)
 [2004-07-26 13:05 UTC] nlopess@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

fixed by Jakub Vrana.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 19:01:28 2024 UTC