Support Joomla!

references:joomla.framework:base:jobject-getproperties

Table of Contents

getProperties

API Package Subpackage Class Method Reference Last reviewed Doc status
API Home Package Joomla.Framework Subpackage Base Class JObject Method getProperties Reference getProperties() Never Work in Progress

This function returns an array of property names.

Syntax

array getProperties ($public = true)

$public boolean whether to include private properties in the result

See also: * JObject::set * JObject::get * JObject::setProperties

Examples

The method is designed to only return the public properties of an object. Since the concept of public, protected, and private properties is only available as of PHP5, the underscore character is used as a prefix to mark properties visually as private. This is common practice in PHP land and not specific to Joomla!

Example 1

$myobj = new JObject();

// set some properties
$myobj->set('name', 'Anonymous');
$myobj->set('version', '1.0');
$myobj->set('_secret', '4711');

print_r( $myobj->getProperties() );

will produce:

Result 1

Array
(
    [name] => Anonymous
    [version] => 1.0
)

In order to retrieve all properties from an object, you must provide false for the ‘$public’ argument.

Example 2

print_r( $myobj->getProperties(false) );

will produce:

Result 1

Array
(
    [_errors] => Array 
                 (
                 )
    [name] => Anonymous
    [version] => 1.0
    [_secret] => 4711
)

The ‘_errors’ property shown in this output is declared in the JObject class.


Discussion

Full name:
E-Mail:
 
references/joomla.framework/base/jobject-getproperties.txt (351 views) · Last modified: 2007/09/22 02:51