php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62874 getDefaultValue() fails
Submitted: 2012-08-20 13:22 UTC Modified: 2012-08-21 10:08 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: karsten at typo3 dot org Assigned: laruence (profile)
Status: Closed Package: Reflection related
PHP Version: 5.3.16 OS: OS X
Private report: No CVE-ID: None
 [2012-08-20 13:22 UTC] karsten at typo3 dot org
Description:
------------
If isDefaultValueAvailable() returns TRUE I expect to be able to call 
getDefaultValue()

Test script:
---------------
<?php
class a {
	protected function test(array $a = NULL, $b, array $c = NULL) {}
}

$class = new ReflectionClass('a');
foreach ($class->getMethods() as $method) {
	foreach ($method->getParameters() as $p) {
	    echo $p->getName() . "\n";
	    echo "   isDefaultValueAvailable: " . var_export($p->isDefaultValueAvailable(), true) . "\n";
		if ($p->isDefaultValueAvailable()) {
			echo "    default value: " . var_export($p->getDefaultValue(), true) . "\n";
		}
	    echo "    isOptional: " . var_export($p->isOptional(), true) . "\n";
	    echo "    allowsNull: " . var_export($p->allowsNull(), true) . "\n";
	    echo "\n";
	}
}
?>

Expected result:
----------------
a
   isDefaultValueAvailable: true
    default value: NULL
    isOptional: false
    allowsNull: true

b
   isDefaultValueAvailable: false
    isOptional: false
    allowsNull: true

c
   isDefaultValueAvailable: true
    default value: NULL
    isOptional: true
    allowsNull: true

Actual result:
--------------
a
   isDefaultValueAvailable: true

Fatal error: Uncaught exception 'ReflectionException' with message 'Parameter is 
not optional' in test.php on line 12

ReflectionException: Parameter is not optional in test.php on line 12

Call Stack:
    0.0010     646632   1. {main}() test.php:0
    0.0011     651128   2. ReflectionParameter->getDefaultValue() test.php:12

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-20 14:04 UTC] laruence@php.net
hmm,  I fixed a similar bug before, I still think it's a wrong usage..

however I will fix this later.
 [2012-08-20 14:13 UTC] laruence@php.net
-Assigned To: +Assigned To: laruence
 [2012-08-20 14:27 UTC] karsten at typo3 dot org
You mean https://bugs.php.net/62715 - it brought me on track. I have a report for 
my test script ran on 5.4 that results in 
https://gist.github.com/467127b13f987b1633d9, so it seems 
isDefaultValueAvailable() returns false thereā€¦
 [2012-08-21 05:41 UTC] laruence@php.net
-Status: Assigned +Status: Feedback
 [2012-08-21 05:41 UTC] laruence@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2012-08-21 05:42 UTC] laruence@php.net
seems it already be fixed. please try with the 5.3-master snapshot
 [2012-08-21 07:45 UTC] karsten at typo3 dot org
Indeed, my test script runs with the expected output on php5.3-latest.

And the output of 5.3 and 5.4 differ when it comes to isDefaultValueAvailable() - 
see https://gist.github.com/724fbc1e29fb7b0bad59 - failed because on 5.4.0 the bug 
#62715 did still exist.
 [2012-08-21 10:08 UTC] laruence@php.net
-Status: Feedback +Status: Closed
 [2012-08-21 10:08 UTC] laruence@php.net
yeah, that bug was fixed after 5.4.0

since problem gone, I will close this
 [2012-08-21 12:26 UTC] crash__ at hotmail dot fr
I have a similar bug with the doctrine's generation proxies on GNU/Linux.

So can we expect a 5.3.17 version soon?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC