Bug #73742 [Opn->Nab]: ReflectionParameter.getDefaultValue returning wrong value when leading zeros.

From: Date: Thu, 15 Dec 2016 01:57:51 +0000
Subject: Bug #73742 [Opn->Nab]: ReflectionParameter.getDefaultValue returning wrong value when leading zeros.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206021@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73742&edit=1

 ID:                 73742
 Updated by:         requinix@php.net
 Reported by:        vinipickrodt at gmail dot com
 Summary:            ReflectionParameter.getDefaultValue returning wrong
                     value when leading zeros.
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Reflection related
 Operating System:   Windows 10
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2016-12-15 01:31:02] 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
?>



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=73742&edit=1


Thread (2 messages)

« previous php.bugs (#206021) next »