?

User tests: Successful: Unsuccessful:

avatar nibra
nibra
23 Oct 2014

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] Indirect modification of overloaded property is possible
[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.

avatar nibra nibra - open - 23 Oct 2014
avatar jissues-bot jissues-bot - change - 23 Oct 2014
Labels Added: ?
avatar mbabker
mbabker - comment - 23 Oct 2014

General testing instructions

As JObject is used quite heavily in the CMS (the legacy MVC classes, JTable, and plugin classes being easy examples), general testing of this patch can be accomplished through installing it and using the CMS in your usual configuration and with your usual favored extensions.

Developers

For developers extending and using JObject, you would want to verify that all data storage and retrieval continues to return your expected data sets.

avatar compojoom
compojoom - comment - 24 Oct 2014

I applied the patch, but then I ran into the following issues:
http://localhost/pbf/administrator/index.php?option=com_banners
Notice: Indirect modification of overloaded property BannersModelBanners::$_forms has no effect in C:\xampp\htdocs\pbf\libraries\legacy\model\list.php on line 416

http://localhost/pbf/administrator/index.php?option=com_joomlaupdate
Notice: Indirect modification of overloaded property JoomlaupdateViewDefault::$ftp has no effect in C:\xampp\htdocs\pbf\administrator\components\com_joomlaupdate\controller.php on line 43

Fatal error: Cannot assign by reference to overloaded object in C:\xampp\htdocs\pbf\administrator\components\com_joomlaupdate\controller.php on line 43

http://localhost/pbf/administrator/index.php?option=com_tags
Notice: Indirect modification of overloaded property TagsViewTags::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_tags\views\tags\view.html.php on line 44
Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_tags\views\tags\tmpl\default.php on line 129

http://localhost/pbf/administrator/index.php?option=com_content

Notice: Indirect modification of overloaded property ContentModelArticles::$_forms has no effect in C:\xampp\htdocs\pbf\libraries\legacy\model\list.php on line 416

http://localhost/pbf/administrator/index.php?option=com_categories&extension=com_content
Notice: Indirect modification of overloaded property CategoriesModelCategories::$_forms has no effect in C:\xampp\htdocs\pbf\libraries\legacy\model\list.php on line 416

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Notice: Indirect modification of overloaded property CategoriesViewCategories::$ordering has no effect in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\view.html.php on line 54

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 108

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pbf\administrator\components\com_categories\views\categories\tmpl\default.php on line 122

http://localhost/pbf/administrator/index.php?option=com_content&view=featured
Notice: Indirect modification of overloaded property ContentModelFeatured::$_forms has no effect in C:\xampp\htdocs\pbf\libraries\legacy\model\list.php on line 416

http://localhost/pbf/administrator/index.php?option=com_installer
Notice: Indirect modification of overloaded property InstallerViewInstall::$ftp has no effect in C:\xampp\htdocs\pbf\administrator\components\com_installer\controller.php on line 45

Fatal error: Cannot assign by reference to overloaded object in C:\xampp\htdocs\pbf\administrator\components\com_installer\controller.php on line 45

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4909.

avatar nibra
nibra - comment - 24 Oct 2014

I identified the cause (see this answer on StackOverflow). Pull Request will be changed accordingly later this day.

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4909.

avatar nibra
nibra - comment - 24 Oct 2014

@compojoom, would you please try again with the updated Pull Request?

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4909.

avatar compojoom
compojoom - comment - 24 Oct 2014

Now the notices are no longer there, but I still get fatal error in com_joomlaupdate and in com_installer
Fatal error: Cannot assign by reference to overloaded object in C:\xampp\htdocs\pbf\administrator\components\com_joomlaupdate\controller.php on line 43
Fatal error: Cannot assign by reference to overloaded object in C:\xampp\htdocs\pbf\administrator\components\com_installer\controller.php on line 45

avatar nibra nibra - change - 24 Oct 2014
The description was changed
avatar nibra
nibra - comment - 24 Oct 2014

Fixed the reference assignment in the controllers. Unfortunately, there is no general solution that can be implemented in JObject. Assignments with =& to not yet existing properties have to be avoided.

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4909.

avatar compojoom
compojoom - comment - 25 Oct 2014

Okay, then how do we handle the assignment issue? If this breaks in joomla core extensions I fear that it will brake in more than a few 3rd party extensions as well... If we cannot fix this with code, then we need good docs on this, so developers can update their code.

avatar nibra
nibra - comment - 25 Oct 2014

The problem only occurs, when a value is assigned by reference to a property, which does not yet exist. The two places in the core were actually only one (duplicated code), where the assignment was wrong - the value was a boolean returned by a method (not even a reference). So I don't share your fear (in that degree), since only poorly designed code will be revealed.

But I agree, it has to be documented. Is there a place where we gather information pieces for the "known issues", which are published with each release?

avatar Bakual
Bakual - comment - 25 Oct 2014

So I don't share your fear (in that degree), since only poorly designed code will be revealed.

It's really simple: If you need to adjust core (or any other 3rd party extension) for it to work, then there is no way that can go into Joomla 3.x. It would be a backward compatibility break. Even if it would only happen for poorly written code. In fact I can assure you there are many poorly written examples out there. And if we even have this in core, who do we want to blame?

But I agree, it has to be documented. Is there a place where we gather information pieces for the "known issues", which are published with each release?

If there are "known issues" before release, the issues have to be fixed. There is no place to document them because we don't release that stuff knowingly.

The earliest would be 4.0, but by then we would like to rmeove it anyway.

avatar nibra
nibra - comment - 27 Oct 2014

That's bad - but reasonable. Closing the PR.

avatar nibra nibra - close - 27 Oct 2014
avatar nibra nibra - close - 27 Oct 2014
avatar nibra nibra - change - 27 Oct 2014
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2014-10-27 12:56:48
avatar compojoom
compojoom - comment - 27 Oct 2014
avatar nibra nibra - head_ref_deleted - 18 Jul 2015

Add a Comment

Login with GitHub to post a comment