# ReflectionProperty change between 5.1 and 5.2

- Thread: https://externals.io/message/26296
- Original archive: https://news-web.php.net/php.internals/26296
- Started by Morten Fangel on 2006-11-03T10:03:06+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #26296 — Morten Fangel — 2006-11-03T10:03:06+00:00

URL: https://externals.io/message/26296#26296

Hi,

Lets say I have a class

class MyClass
  protected $foo = 'bar';
}

In PHP 5.1 I could do

$myobj = new MyClass();
$c = new ReflectionClass($myobj);
$p = $c->getProperty('foo');
echo $p->getValue($myobj); // bar

But in PHP 5.2 I now get an exception with "Cannot access non-public member 
MyClass::foo"

Yes, I do know that "protected" is supposed to make the variable internal 
(hence non-public), but shouldn't the ReflectionAPI enable one to "reverse 
engineer" all classes and properties - including the ones hidden in run-time? 
And if not, then how come it was like this in 5.1?

-fangel
