joomla/joomla-cms — pull request #4853 by nibra (2014-10-19 15:17:11+00:00)
Title: JObject refactoring

Refactored JObject to transparently remove leading underscores from property names on access, if needed.

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] isset() works on JObject as on stdClass
[x] isset() works on JObject as on stdClass with multiple levels
[x] empty() works on JObject as on stdClass
[x] empty() works on JObject as on stdClass with multiple levels
[x] unset() of existing properties works on JObject as on stdClass
[x] unset() of non-existing properties works on JObject as on stdClass
[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

as proved by the accompanied tests.