php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37816 ReflectionProperty does not throw exception when accessing protected attribute
Submitted: 2006-06-15 11:05 UTC Modified: 2006-07-10 00:19 UTC
From: pierrealain dot bourdil at free dot fr Assigned: helly (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.1.* OS: *
Private report: No CVE-ID: None
 [2006-06-15 11:05 UTC] pierrealain dot bourdil at free dot fr
Description:
------------
 First , i hope to really submit a bug, at least i've done my best to check it.
  
 i've made a class that contains other class, with dynamic adding,removing possibilities, save,restaure from session, and which use  __call,__get,__set method. 
 
 Within __get method, i instanciate ReflectionProperty. 
When i access a protected property, using ReflectionProperty->getValue, i expect to catch an exception, but i don't. 
  I can access this property. It works perfectly with ReflectionMethod, but no with ReflectionProperty. 

Reproduce code:
---------------
$rp=new ReflectionProperty($myClass,value);
try{
  if ($rp->isStatic())
       return $rp->getValue(null);
  else
       return $rp->getValue(self::$instance->aClasses[$myClass]);
}catch( Exception $e){
    echo $e->getMessage();
    return null;
}

now a portion the class which contains property that i tri to access
protected $pp;
public function __construct(){
     $this->pp="pp";
}


Expected result:
----------------
this is what i expect, but for method, 
Trying to invoke protected method test::testFunction from scope ReflectionMethod

i think i would expect something like that
Trying to access protected property test::pp from scope Reflectionproperty

Actual result:
--------------
__get : pp

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-15 11:22 UTC] bjori@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2006-06-15 12:12 UTC] pierrealain dot bourdil at free dot fr
bjori, the script is at 
http://pastebin.com/710566

best regards
 [2006-06-19 11:20 UTC] tony2001@php.net
No need for huge reproduce scripts, you need only this:
<?php
class test{
        private $pp = 1;
}

$t = new test;
$rp = new ReflectionProperty("test", "pp");
var_dump($rp->getValue($t));
?>

Marcus, you changed this: http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/php_reflection.c?r1=1.185&r2=1.186
 [2006-07-09 23:27 UTC] helly@php.net
There is some disabled code here which would fix the issue without the need to bailout.

marcus@zaphod /usr/src/php-cvs $ php -r 'class T{protected $p=2;} $o=new T; $r=new ReflectionProperty($o,"p"); var_dump($r->getValue($o));'
make: `sapi/cli/php' is up to date.

Fatal error: Cannot use array returned from ReflectionException::__get('trace') in write context in Unknown on line 0
 [2006-07-10 00:19 UTC] helly@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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC