RPCL Components Properties

From RadPHP XE2 Documentation
Jump to: navigation, search

In PHP, class properties can be public, protected or private. The implications of each of those levels of PHP properties visibility is better explained in PHP official documentation: php.net/manual/en/language.oop5.visibility.php.

For RPCL components, there are two component properties visibility levels to consider (see below). Component properties must still have a PHP visibility level, that does not change. Component visibility levels are a different way to let you control the way users can access component properties, no matter what the PHP visibility level of those properties is. Also, notice that any component property can be both public and published, which might render convinient in certain situations.

Public Properties

Public properties are suitable for base components, those intented to be extended by child components. Base components usually retain the most of the functionality, and you can then publish on child components only the inherited properties you need.

You can create a public property like this:

protected $_testproperty = 'default';
function readTestProperty() { return $this->_testproperty; }
function writeTestProperty($value) { $this->_testproperty=$value; }

You can then work with public properties like this:

$MyFirstComponent->TestProperty = 'value';
echo $MyFirstComponent->TestProperty;

That is, read and write methods are interfaces to the protected $_testproperty variable, and are automatically called thanks to PHP magic functions ( __set() and __get()).

Published Properties

Published properties are the only ones displayed in the Object Inspector, so you must use this properties if you want to be able to change them on design time.

To publish a property, just provide getter and setter methods for it:

function getTestProperty() { return $this->readTestProperty(); }
function setTestProperty($value) { $this->writeTestProperty($value); }

Providing a getter for default property value can be also convenient:

function defaultTestProperty() { return 'value'; }

Note in these examples functions call read and write methods. So these getter, setter and default getter functions are just interfaces to public properties. But you can publish a non-public property instead, there is no restriction to which properties can be or not published. For example, you could publish a protected property like this:

protected $property;
function getProperty() { return $this->property; }
function setProperty($value) { $this->property = $value; }
function defaultProperty() { return 'value'; }
Personal tools