php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73742 ReflectionParameter.getDefaultValue returning wrong value when leading zeros.
Submitted: 2016-12-15 01:31 UTC Modified: 2016-12-15 01:57 UTC
From: vinipickrodt at gmail dot com Assigned:
Status: Not a bug Package: Reflection related
PHP Version: Irrelevant OS: Windows 10
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vinipickrodt at gmail dot com
New email:
PHP Version: OS:

 

 [2016-12-15 01:31 UTC] vinipickrodt at gmail dot com
Description:
------------
ReflectionParameter.getDefaultValue returning wrong value when default parameter have leading zeros.

Test script:
---------------
<?php
class Foo
{
	public function Bar($n1 = 09, $n2 = 9){
		return 0;
	}
}


$r = new ReflectionObject(new Foo());
$m = $r->getMethod("Bar");
$p1 = $m->getParameters()[0];
$p2 = $m->getParameters()[1];
echo "p1=".$p1->getDefaultValue(); //not ok. expected = 9, returning 0.
echo "<br>";
echo "p2=".$p2->getDefaultValue(); //ok = 9
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-15 01:57 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-12-15 01:57 UTC] requinix@php.net
A leading zero means octal notation - base 8. 09 is invalid octal so PHP substitutes 0.

https://en.wikipedia.org/wiki/Octal
http://php.net/manual/en/language.types.integer.php

ReflectionParameter is simply how you're learning about it. You could have done
  echo 09; // 0
and discovered it that way.

If you were using PHP 7 then it would have shown you a parse error instead:
  Parse error: Invalid numeric literal in <file> on line 4
https://3v4l.org/vqqMY
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 13:01:27 2024 UTC