php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37682 ReflectionObject::getProperties() does not return dynamic properties
Submitted: 2006-06-02 17:31 UTC Modified: 2006-08-25 17:23 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: ncosta at alum dot rpi dot edu Assigned: johannes (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.1.4 OS: Irrelevant
Private report: No CVE-ID: None
 [2006-06-02 17:31 UTC] ncosta at alum dot rpi dot edu
Description:
------------
The method ReflectionObject::getProperties() fails to return 
any dynamically-set properties of an object. The Reflection 
API is aware of them, because they appear in an export (as 
shown below) and are found by ReflectionObject::hasProperty(), 
but they do not appear in the array returned by getProperties
(). There is no "getDynamicProperties()" method, and so 
without specific documentation it stands to reason that 
getProperties() should return ALL of an object's visible 
properties, both compile-time and run-time.

Reproduce code:
---------------
class Foo
{
    public $bar;
}

$p = new Foo;
$p->baz = 4;

$r = new ReflectionObject( $p );
Reflection::export( $r );
print_r( $r->getProperties() );

Expected result:
----------------
Object of class [  class Foo ] {
  @@ /var/www/test.php 3-6

  - Constants [0] {
  }

  - Static properties [0] {
  }

  - Static methods [0] {
  }

  - Properties [1] {
    Property [  public $bar ]
  }

  - Dynamic properties [1] {
    Property [  public $baz ]
  }

  - Methods [0] {
  }
}

Array
(
    [0] => ReflectionProperty Object
        (
            [name] => bar
            [class] => Foo
        )
    [1] => ReflectionProperty Object
        (
            [name] => baz
            [class] => Foo
        )
)

Actual result:
--------------
Object of class [  class Foo ] {
  @@ /var/www/test.php 3-6

  - Constants [0] {
  }

  - Static properties [0] {
  }

  - Static methods [0] {
  }

  - Properties [1] {
    Property [  public $bar ]
  }

  - Dynamic properties [1] {
    Property [  public $baz ]
  }

  - Methods [0] {
  }
}

Array
(
    [0] => ReflectionProperty Object
        (
            [name] => bar
            [class] => Foo
        )
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-02 19:30 UTC] johannes@php.net
Already on my personal todo :-)
 [2006-08-25 17:23 UTC] bjori@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.

Marcus fixed this couple of months ago in HEAD and 5_2
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/php_reflection.c?r1=1.164.2.33.2.7&r2=1.164.2.33.2.8&pathrev=PHP_5_2
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 01:01:30 2024 UTC