? ? Pending

User tests: Successful: Unsuccessful:

avatar pe7er
pe7er
26 Apr 2022

Pull Request to fix on PHP 8.0 an issue with "Notice: Only variable references should be returned by reference in /srv/www/joomla/joomla-cms/libraries/src/MVC/Model/BaseDatabaseModel.php on line 418"

Testing Instructions

Environment:

  • PHP Version: 8.0.17
  • Web Server: Apache/2.4.53 (Unix) OpenSSL/1.1.1n
  • Joomla! Version: Joomla! 4.2.0-alpha2-dev Development [ Kuamini ] 29-March-2022 18:41 GMT

In a fresh installed Joomla 4 with the sample data for testing, under "Menus" open a menu item like "All Modules".
Or directly go to: administrator/index.php?option=com_menus&view=items&menutype=all-modules
(most of the other menu items have this issue)
and see the notice appear

Notice: Only variable references should be returned by reference in /srv/www/joomla/joomla-cms/libraries/src/MVC/Model/BaseDatabaseModel.php on line 418

Actual result BEFORE applying this Pull Request

Notice: Only variable references should be returned by reference in /srv/www/joomla/joomla-cms/libraries/src/MVC/Model/BaseDatabaseModel.php on line 418

before-pr

Expected result AFTER applying this Pull Request

after-pr

avatar pe7er pe7er - open - 26 Apr 2022
avatar pe7er pe7er - change - 26 Apr 2022
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 26 Apr 2022
Category Libraries
avatar laoneo
laoneo - comment - 26 Apr 2022

Thanks. I guess this needs a bit more rethinking, because of undeclared variable references.

avatar pe7er
pe7er - comment - 26 Apr 2022

Thanks, I was already afraid that removing the ampersand before the function name would be too easy and probably not be the definitive solution :-)

avatar toivo
toivo - comment - 27 Apr 2022

I have tested this item successfully on c5d5b8e

Tested successfully in Joomla 4.2.0-alpha3-dev of 27 April in Wampserver 3.2.8 using PHP 8.0.15.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/37661.
avatar toivo toivo - test_item - 27 Apr 2022 - Tested successfully
avatar joeforjoomla
joeforjoomla - comment - 27 Apr 2022

I have tested this item successfully on c5d5b8e


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

avatar joeforjoomla joeforjoomla - test_item - 27 Apr 2022 - Tested successfully
avatar laoneo
laoneo - comment - 27 Apr 2022

Thanks, I was already afraid that removing the ampersand before the function name would be too easy and probably not be the definitive solution :-)

I guess removing the ampersand is fine, but we need to adapt the unit test

avatar laoneo
laoneo - comment - 27 Apr 2022

Can you replace the unit test function with this more real world scenario:

	public function testNotDeclaredVariable()
	{
		$model = new class(['dbo' => $this->createStub(DatabaseInterface::class)], $this->createStub(MVCFactoryInterface::class)) extends BaseDatabaseModel
		{
			public function cache($key, $value)
			{
				if (!isset($this->test[$key]))
				{
					$this->test[$key] = $value;
				}

				return $this->test[$key];
			}
		};

		$this->assertEquals('test', $model->cache(1, 'test'));
	}
avatar laoneo laoneo - change - 27 Apr 2022
Labels Added: ? ?
avatar joomla-cms-bot joomla-cms-bot - change - 28 Apr 2022
Category Libraries Libraries Unit Tests
avatar pe7er
pe7er - comment - 28 Apr 2022

I've added your unit test to my PR. Thanks @laoneo !

avatar laoneo laoneo - change - 29 Apr 2022
Labels Added: ?
Removed: ?
avatar laoneo laoneo - change - 29 Apr 2022
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2022-04-29 12:23:34
Closed_By laoneo
avatar laoneo laoneo - close - 29 Apr 2022
avatar laoneo laoneo - merge - 29 Apr 2022
avatar laoneo
laoneo - comment - 29 Apr 2022

Thanks!

Add a Comment

Login with GitHub to post a comment