DataObject

Implements DumpableInterface, IteratorAggregate, JsonSerializable, Countable

DataObject is a class that is used to store data but allowing you to access the data by mimicking the way PHP handles class properties.

since

1.0

package

Joomla Framework

Methods

__construct

The class constructor.

__construct(mixed properties = []) : mixed
since

1.0

throws

\InvalidArgumentException

Arguments

properties

mixedEither an associative array or another object by which to set the initial properties of the new object.

Response

mixed

__get

The magic get method is used to get a data property.

__get(string property) : mixed

This method is a public proxy for the protected getProperty method.

Note: Magic __get does not allow recursive calls. This can be tricky because the error generated by recursing into __get is "Undefined property: {CLASS}::{PROPERTY}" which is misleading. This is relevant for this class because requesting a non-visible property can trigger a call to a sub-function. If that references the property directly in the object, it will cause a recursion into __get.

see DataObject::getProperty()
since

1.0

Arguments

property

stringThe name of the data property.

Response

mixedThe value of the data property, or null if the data property does not exist.

__isset

The magic isset method is used to check the state of an object property.

__isset(string property) : bool
since

1.0

Arguments

property

stringThe name of the data property.

Response

bool

__set

The magic set method is used to set a data property.

__set(string property, mixed value) : void

This is a public proxy for the protected setProperty method.

see DataObject::setProperty()
since

1.0

Arguments

property

stringThe name of the data property.

value

mixedThe value to give the data property.

__unset

The magic unset method is used to unset a data property.

__unset(string property) : void
since

1.0

Arguments

property

stringThe name of the data property.

bind

Binds an array or object to this object.

bind(mixed properties, bool updateNulls = true) : $this
since

1.0

throws

\InvalidArgumentException

Arguments

properties

mixedAn associative array of properties or an object.

updateNulls

boolTrue to bind null values, false to ignore null values.

Response

$this

count

Count the number of data properties.

count() : int
since

1.0

Response

intThe number of data properties.

dump

Dumps the data properties into an object, recursively if appropriate.

dump(int depth = 3, \SplObjectStorage dumped = null) : \stdClass
since

1.0

Arguments

depth

intThe maximum depth of recursion (default = 3). For example, a depth of 0 will return a stdClass with all the properties in native form. A depth of 1 will recurse into the first level of properties only.

dumped

\SplObjectStorageAn array of already serialized objects that is used to avoid infinite loops.

Response

\stdClass

dumpProperty

Dumps a data property.

dumpProperty(string property, int depth, \SplObjectStorage dumped) : mixed

If recursion is set, this method will dump any object implementing DumpableInterface (like DataObject and DataSet); it will convert a DateTimeInterface object to a string; and it will convert a Joomla\Registry\Registry to an object.

since

1.0

Arguments

property

stringThe name of the data property.

depth

intThe current depth of recursion (a value of 0 will ignore recursion).

dumped

\SplObjectStorageAn array of already serialized objects that is used to avoid infinite loops.

Response

mixedThe value of the dumped property.

getIterator

Gets this object represented as an ArrayIterator.

getIterator() : \ArrayIterator

This allows the data properties to be access via a foreach statement.

see IteratorAggregate::getIterator()
since

1.0

Response

\ArrayIterator

getProperty

Gets a data property.

getProperty(string property) : mixed
see DataObject::__get()
since

1.0

Arguments

property

stringThe name of the data property.

Response

mixedThe value of the data property.

jsonSerialize

Gets the data properties in a form that can be serialised to JSON format.

jsonSerialize() : string
since

1.0

Response

string

setProperty

Sets a data property.

setProperty(string property, mixed value) : mixed

If the name of the property starts with a null byte, this method will return null.

see DataObject::__set()
since

1.0

Arguments

property

stringThe name of the data property.

value

mixedThe value to give the data property.

Response

mixedThe value of the data property.

Properties

properties

The data object properties.

since

1.0

Type(s)

array