joomla/joomla-cms — pull request #4909 by nibra (2014-10-23 23:06:39+00:00)
Title: Refactored JObject, added tests

Refactored JObject to transparently remove leading underscores from property names on access, if needed.
Introduced class constants `JObject::RETURN_PUBLIC` and `JObject::RETURN_ALL` for use with `JObject::getProperties()` for better inline documentation.

## Why the refactoring?

In PHP4, the visibility of all properties was public, so it was agreed on to signal private properties by prefixing its name with an underscore. Since PHP5 supports visibility scopes, this no longer is appropriate, and property names shall not start with an underscore.

In order to achieve that, requesting a non-existing underscored property on the refactored JObject will return the value of the corresponding property without the underscore.

JObject now has these features:

[x] Properties can be set in a bulk
[x] Properties can be set during construction
[x] Set properties returns false on unsuitable parameter
[x] Set properties returns true on array parameter
[x] Set properties returns true on object parameter
[x] Setting a single property returns the previous value
[x] A single property can be set directly
[x] By default, getProperties() returns only public properties
[x] With RETURN_ALL set, getProperties() also returns protected properties
[x] Even with RETURN_ALL set, getProperties() does not return static properties
[x] Even with RETURN_ALL set, getProperties() does not return private properties
[x] A non-existent property defaults to null
[x] A non-existent property defaults to the provided default value
[x] A defined value will not get overwritten by get()
[x] A property can be accessed directly
[x] A default can be defined for a property
[x] A defined value will not get overwritten by def()
[x] Cast to string returns class name
[x] [deprecated] Errors can be set
[x] [deprecated] getError() returns the last error by default
[x] [deprecated] Errors can be retrieved by index
[x] [deprecated] Accessing an undefined error index returns 0
[x] [deprecated] Numerical errors can be retrieved unchanged
[x] [deprecated] Numerical errors can be retrieved as string
[x] [deprecated] Exceptions can be retrieved unchanged
[x] [deprecated] Exceptions can be retrieved as string
[x] [deprecated] Underscored properties are redirected correctly
[x] [deprecated] Not underscored properties are redirected correctly
[x] [deprecated] isset() works on JObject as on stdClass
[x] [deprecated] isset() works on JObject as on stdClass with multiple levels
[x] [deprecated] empty() works on JObject as on stdClass
[x] [deprecated] empty() works on JObject as on stdClass with multiple levels
[x] [deprecated] unset() of existing properties works on JObject as on stdClass
[x] [deprecated] unset() of non-existing properties works on JObject as on stdClass

as proved by the accompanied tests.