php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42258 MethodParameter::getDefaultValue() return null
Submitted: 2007-08-09 15:30 UTC Modified: 2007-08-17 14:24 UTC
From: vincent dot hoen at gmail dot com Assigned: johannes (profile)
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.4RC1 OS: windows xp
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: vincent dot hoen at gmail dot com
New email:
PHP Version: OS:

 

 [2007-08-09 15:30 UTC] vincent dot hoen at gmail dot com
Description:
------------
ReflectionProperty::getDefaultValue() returns null only if the property is not static.

Reproduce code:
---------------
class test{
	public $test = 'aze';
	static $stat = 'ic';
}


$class = new ReflectionClass('test');
foreach($class->getProperties() as $k => $v){
    var_dump($v->getValue($class));
}

Expected result:
----------------
string 'aze' (length=3)

string 'ic' (length=2)


Actual result:
--------------
null

string 'ic' (length=2)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-17 13:47 UTC] jani@php.net
Assigned to the maintainer of reflection extension.
 [2007-08-17 14:24 UTC] johannes@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

Your code is wrong. The parameter to getValue has to be an instance of the reflected class, not the reflection object. Try

<?php
class test{
        public $test = 'aze';
        static $stat = 'ic';
}


$class = new ReflectionClass('test');
foreach($class->getProperties() as $k => $v){
    var_dump($v->getValue(new test()));
}
?>

instead.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC