[ create a new paste ] login | about

Link: http://codepad.org/lx8ecZMz    [ raw code | output | fork ]

PHP, pasted on Jul 23:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php

abstract class A
{
    private $b = 'c';


    public function __get($a){

    }
}

class B extends A{}

$obj = new B();

$r = new ReflectionObject($obj);
$p = $r->getProperty('b');
$p->setAccessible(true); // <--- you set the property to public before you read the value

var_dump($p->getValue($obj));


Output:
1
2
3
4
5
6

Fatal error: Uncaught exception 'ReflectionException' with message 'Property b does not exist' in /t.php:18
Stack trace:
#0 /t.php(18): ReflectionClass->getProperty('b')
#1 {main}
  thrown in /t.php on line 18


Create a new paste based on this one


Comments: