You are here: PHP5.1 Reflection Reading protected Property « PHP Programming Language « IT news, forums, messages
PHP5.1 Reflection Reading protected Property

Posted by Jens on 02/15/06 14:23

Hello,

i am just trying to get familiar with the Reflection-Api.
I want to access a protected property of my class using the
getValue-method of ReflectionProperty-Class. When i execute the code i
get the Exception "Cannot access non-public member". Shouldnt it be
possible to access a property from within the same class?
Is using public getter and setter methods the only way to acces that
property?

Here is my code:

thanxx

class Test{

/**
* id *
* @access protected
* @var int
*/
protected $id = 0;

/**
* Name
*
* @access protected
* @var String
*/
protected $name = null;

protected $pkfield = null;

/**
* ...
*
*
* @access public
* @author
* @return
*/
public function __construct()
{
$this->pkfield="id";
}

/**
* Die Funktion ...
*
*
* @access public
* @author
* @return
*/
public function check()
{
try{

$rclass = new ReflectionClass(get_class());
$prop=$rclass->getProperty($this->pkfield);
//Reading Value of id
echo($this->pkfield . "=" . $prop->getValue($this));
}catch(Exception $e1){
echo("Error: " . $e1->getMessage());
}

}
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация