php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47254 Wrong Reflection for extends class
Submitted: 2009-01-30 23:15 UTC Modified: 2009-04-27 20:04 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: ivan1986 at list dot ru Assigned: felipe
Status: Closed Package: Reflection related
PHP Version: 5.*, 6CVS (2009-04-25) OS: *
Private report: No CVE-ID:
 [2009-01-30 23:15 UTC] ivan1986 at list dot ru
Description:
------------
I test this in two version:

ivan@ivan1986:~% /usr/bin/php -v
PHP 5.2.6-3 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan 25 2009 00:51:23)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
    with XCache v1.2.2, Copyright (c) 2005-2007, by mOo

ivan@ivan1986:~% php -v
PHP 6.0.0-dev (cli) (built: Nov  8 2008 02:31:17)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2008 Zend Technologies

in CVS error now.

Reproduce code:
---------------
<?php

class A
{
	protected function a() {}
	
}

class B extends A
{
	public function b() {}
}

$B = new B();
$R = new ReflectionObject($B);
$m = $R->getMethods();
print_r($m);

?>

Expected result:
----------------
Array
(
    [0] => ReflectionMethod Object
        (
            [name] => b
            [class] => B
        )

    [1] => ReflectionMethod Object
        (
            [name] => a
            [class] => A
        )

)


Actual result:
--------------
Array
(
    [0] => ReflectionMethod Object
        (
            [name] => b
            [class] => B
        )

    [1] => ReflectionMethod Object
        (
            [name] => a
            [class] => B
        )

)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-31 19:44 UTC] felipe@php.net
Hi Marcus, is this actually the behavior expected?
As we have the 'class' array key in the return, I believe that is really a bug.

Anyway here is a simple fix:
http://felipe.ath.cx/diff/bug47254.diff
 [2009-04-27 16:48 UTC] jani@php.net
Of course it's a bug, just commit your fix..
 [2009-04-27 18:23 UTC] ivan1986 at list dot ru
Hello!
As i now C and how i understand source fix may by simpled:

-	ZVAL_STRINGL(classname, ce->name, ce->name_length, 1);
+	ZVAL_STRINGL(classname, method->common.scope->name, method->common.scope->name_length, 1);

-	ZVAL_STRINGL(classname, ce->name, ce->name_length, 1);
+	ZVAL_STRINGL(classname, prop->ce->name, prop->ce->name_length, 1);
 [2009-04-27 20:04 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fixed in 5.2, 5.3 and HEAD.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Mon Apr 21 00:02:04 2014 UTC