joomla-extensions / patchtester

Patch testing extension for the Joomla! CMS
https://issues.joomla.org
GNU General Public License v2.0
48 stars 44 forks source link

[PHP 8.1] Deprecated: strtoupper() in libraries\src\MVC\Model\ListModel.php on line 586 #341

Closed toivo closed 1 year ago

toivo commented 2 years ago

Steps to reproduce the issue

Set the level of error reporting to 'Maximum'. Open Patch Tester. Click the button Fetch Data.

Expected result

No error messages.

Actual result

A Deprecated error is displayed at the top of the page administrator/index.php?option=com_patchtester ( ! ) Deprecated: strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated in C:\www\joomla41\libraries\src\MVC\Model\ListModel.php on line 586

The same Deprecated error is displayed at the top of the modal 'Fetching Github Data'.

System information (as much as possible)

Joomla 4.1.5-dev of 1 June, Wampserver 3.2.9 with PHP 8.1.6

Additional comments

This Deprecated messages is not displayed when using PHP 8.0.15

alikon commented 2 years ago

well i've got a slightly different deprecated message

PHP Deprecated: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /shared/httpd/test/zzz/libraries/vendor/joomla/string/src/phputf8/mbstring/core.php on line 24

alikon commented 2 years ago

can you check #342 if solves for you too

ghost commented 2 years ago

Changed the GitHub Repository to 'Patch Tester Component' or to 'Custom > joomla-extensions/patchtester' don't fetch pr's to test.

I experienced the same error as @toivo using patchtester 4.2.1, php 8.1.6.

N6REJ commented 2 years ago

Several pr's addressing the deprecation warnings... https://github.com/joomla/joomla-cms/pull/38917 ( Fixes php 8.1 strtoupper deprecation error ) https://github.com/joomla/joomla-cms/pull/38918 ( Fixes str_replace deprecation warning in php 8.1 ) https://github.com/joomla-framework/string/pull/42 ( Fixes mb_strlen deprecation warning with php 8.1 )

roland-d commented 2 years ago

So I have been testing this but I am unable to get any of the errors using Joomla 4.2.3 and PHP 8.1.0. I have tested this with both the Joomla repo and Patch Tester repo to pull issues in.

Do you still get these errors?

toivo commented 2 years ago

The error is displayed at the top of list and also in the modal 'Fetching Github Data':
Deprecated: strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated in C:\www\joomla4test\libraries\src\MVC\Model\ListModel.php on line 543

toivo commented 2 years ago

Call stacks from three different Deprecated messages:

Deprecated: strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated in C:\www\joomla4test\libraries\src\MVC\Model\ListModel.php on line 543 Call Stack

Time Memory Function Location

1 0.0001 364416 {main}( ) ...\index.php:0 2 0.0001 365184 require_once( 'C:\www\joomla4test\administrator\includes\app.php ) ...\index.php:32 3 0.0108 1085576 Joomla\CMS\Application\CMSApplication->execute( ) ...\app.php:61 4 0.0114 1179088 Joomla\CMS\Application\AdministratorApplication->doExecute( ) ...\CMSApplication.php:294 5 0.0598 2304272 Joomla\CMS\Application\AdministratorApplication->dispatch( $component = ??? ) ...\AdministratorApplication.php:186 6 0.0606 2314840 Joomla\CMS\Component\ComponentHelper::renderComponent( $option = 'com_patchtester', $params = ??? ) ...\AdministratorApplication.php:143 7 0.0651 2425344 Joomla\CMS\Dispatcher\LegacyComponentDispatcher->dispatch( ) ...\ComponentHelper.php:355 8 0.0657 2442240 Joomla\CMS\Dispatcher\LegacyComponentDispatcher::Joomla\CMS\Dispatcher{closure:C:\www\joomla4test\libraries\src\Dispatcher\LegacyComponentDispatcher.php:70-72}( $path = 'C:\www\joomla4test\administrator/components/com_patchtester/patchtester.php' ) ...\LegacyComponentDispatcher.php:73 9 0.0657 2442688 require_once( 'C:\www\joomla4test\administrator\components\com_patchtester\patchtester.php ) ...\LegacyComponentDispatcher.php:71 10 0.0838 2444160 PatchTester\Controller\FetchController->execute( ) ...\patchtester.php:44 11 0.0847 2466272 PatchTester\Model\PullsModel->requestFromGithub( $page = 1 ) ...\FetchController.php:56 12 0.2045 2460256 Joomla\CMS\MVC\Model\BaseModel->getState( $property = ???, $default = ??? ) ...\PullsModel.php:366 13 0.2045 2460256 Joomla\CMS\MVC\Model\ListModel->populateState( $ordering = ???, $direction = ??? ) ...\StateBehaviorTrait.php:59 14 0.2046 2460256 strtoupper( $string = NULL ) ...\ListModel.php:543

( ! ) Deprecated: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated in C:\www\joomla4test\libraries\vendor\joomla\string\src\phputf8\mbstring\core.php on line 24 Call Stack

Time Memory Function Location

1 0.0001 364416 {main}( ) ...\index.php:0 2 0.0001 365184 require_once( 'C:\www\joomla4test\administrator\includes\app.php ) ...\index.php:32 3 0.0108 1085576 Joomla\CMS\Application\CMSApplication->execute( ) ...\app.php:61 4 0.0114 1179088 Joomla\CMS\Application\AdministratorApplication->doExecute( ) ...\CMSApplication.php:294 5 0.0598 2304272 Joomla\CMS\Application\AdministratorApplication->dispatch( $component = ??? ) ...\AdministratorApplication.php:186 6 0.0606 2314840 Joomla\CMS\Component\ComponentHelper::renderComponent( $option = 'com_patchtester', $params = ??? ) ...\AdministratorApplication.php:143 7 0.0651 2425344 Joomla\CMS\Dispatcher\LegacyComponentDispatcher->dispatch( ) ...\ComponentHelper.php:355 8 0.0657 2442240 Joomla\CMS\Dispatcher\LegacyComponentDispatcher::Joomla\CMS\Dispatcher{closure:C:\www\joomla4test\libraries\src\Dispatcher\LegacyComponentDispatcher.php:70-72}( $path = 'C:\www\joomla4test\administrator/components/com_patchtester/patchtester.php' ) ...\LegacyComponentDispatcher.php:73 9 0.0657 2442688 require_once( 'C:\www\joomla4test\administrator\components\compatchtester\patchtester.php ) ...\LegacyComponentDispatcher.php:71 10 0.0838 2444160 PatchTester\Controller\FetchController->execute( ) ...\patchtester.php:44 11 0.0847 2466272 PatchTester\Model\PullsModel->requestFromGithub( $page = 1 ) ...\FetchController.php:56 12 3.8854 11115296 Joomla\CMS\HTML\HTMLHelper::( $key = 'string.truncate', ...$methodArgs = variadic(NULL, 100) ) ...\PullsModel.php:467 13 3.8854 11115792 Joomla\CMS\HTML\HTMLHelper::call( $function = [0 => 'Joomla\CMS\HTML\Helpers\StringHelper', 1 => 'truncate'], $args = [0 => NULL, 1 => 100] ) ...\HTMLHelper.php:126 14 3.8854 11116640 Joomla\CMS\HTML\Helpers\StringHelper::truncate( $text = NULL, $length = 100, $noSplit = ???, $allowHtml = ??? ) ...\HTMLHelper.php:287 15 3.8854 11116640 Joomla\String\StringHelper::strlen( $str = NULL ) ...\StringHelper.php:65 16 3.8854 11116640 utf8_strlen( $str = NULL ) ...\StringHelper.php:262 17 3.8854 11116640 mb_strlen( $string = NULL ) ...\core.php:24

( ! ) Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in C:\www\joomla4test\libraries\src\HTML\Helpers\StringHelper.php on line 132 Call Stack

Time Memory Function Location

1 0.0001 364416 {main}( ) ...\index.php:0 2 0.0001 365184 require_once( 'C:\www\joomla4test\administrator\includes\app.php ) ...\index.php:32 3 0.0108 1085576 Joomla\CMS\Application\CMSApplication->execute( ) ...\app.php:61 4 0.0114 1179088 Joomla\CMS\Application\AdministratorApplication->doExecute( ) ...\CMSApplication.php:294 5 0.0598 2304272 Joomla\CMS\Application\AdministratorApplication->dispatch( $component = ??? ) ...\AdministratorApplication.php:186 6 0.0606 2314840 Joomla\CMS\Component\ComponentHelper::renderComponent( $option = 'com_patchtester', $params = ??? ) ...\AdministratorApplication.php:143 7 0.0651 2425344 Joomla\CMS\Dispatcher\LegacyComponentDispatcher->dispatch( ) ...\ComponentHelper.php:355 8 0.0657 2442240 Joomla\CMS\Dispatcher\LegacyComponentDispatcher::Joomla\CMS\Dispatcher{closure:C:\www\joomla4test\libraries\src\Dispatcher\LegacyComponentDispatcher.php:70-72}( $path = 'C:\www\joomla4test\administrator/components/com_patchtester/patchtester.php' ) ...\LegacyComponentDispatcher.php:73 9 0.0657 2442688 require_once( 'C:\www\joomla4test\administrator\components\compatchtester\patchtester.php ) ...\LegacyComponentDispatcher.php:71 10 0.0838 2444160 PatchTester\Controller\FetchController->execute( ) ...\patchtester.php:44 11 0.0847 2466272 PatchTester\Model\PullsModel->requestFromGithub( $page = 1 ) ...\FetchController.php:56 12 3.8854 11115296 Joomla\CMS\HTML\HTMLHelper::( $key = 'string.truncate', ...$methodArgs = variadic(NULL, 100) ) ...\PullsModel.php:467 13 3.8854 11115792 Joomla\CMS\HTML\HTMLHelper::call( $function = [0 => 'Joomla\CMS\HTML\Helpers\StringHelper', 1 => 'truncate'], $args = [0 => NULL, 1 => 100] ) ...\HTMLHelper.php:126 14 3.8854 11116640 Joomla\CMS\HTML\Helpers\StringHelper::truncate( $text = NULL, $length = 100, $noSplit = ???, $allowHtml = ??? ) ...\HTMLHelper.php:287 15 3.8885 11116640 str_replace( $search = ' </', $replace = '</', $subject = NULL ) ...\StringHelper.php:132 {"success":true,"message":"Processing page 2 of 3 pages of GitHub data","messages":null,"data":{"complete":false,"page":2,"lastPage":3}}

toivo commented 2 years ago

So I have been testing this but I am unable to get any of the errors using Joomla 4.2.3 and PHP 8.1.0. I have tested this with both the Joomla repo and Patch Tester repo to pull issues in.

Do you still get these errors?

The Deprecated messages come up when Error Reporting is 'Maximum' but not with 'Simple'. Using PHP 8.1.9 in Wampserver 3.2.9.

N6REJ commented 2 years ago

So I have been testing this but I am unable to get any of the errors using Joomla 4.2.3 and PHP 8.1.0. I have tested this with both the Joomla repo and Patch Tester repo to pull issues in.

Do you still get these errors?

The 3 errors I created pr's for are with 4.2-dev

roland-d commented 2 years ago

Thanks for your feedback, I will try again with maximum error reporting. I already had it on maximum but I think it depends on which PRs you are getting. Looks like you need to get a PR that has no body, which is also quite impossible as all our PRs have a body. I can simulate that.

N6REJ commented 2 years ago

Thanks for your feedback, I will try again with maximum error reporting. I already had it on maximum but I think it depends on which PRs you are getting. Looks like you need to get a PR that has no body, which is also quite impossible as all our PRs have a body. I can simulate that.

this happens long before the pr's. When you fetch data you will get the errors then.

roland-d commented 2 years ago

I tried again with all error reporting on and saw nothing. So what I did was coded the error reporting into the code so it cannot be changed by anything and forcing the body text of the pull request to null and then I was able to see the deprecation notices.

To fix this, can you try the following:

  1. Open the file /administrator/components/com_patchtester/PatchTester/Model/PullsModel.php
  2. Go to line 365 (or around there) and find the code:
    $this->getDbo()->quote(HTMLHelper::_('string.truncate', $pull->title, 150)),
    $this->getDbo()->quote(HTMLHelper::_('string.truncate', $pull->body, 100)),
  3. Replace it with:
    $this->getDbo()->quote(HTMLHelper::_('string.truncate', ($pull->title ?? ''), 150)),
    $this->getDbo()->quote(HTMLHelper::_('string.truncate', ($pull->body ?? ''), 100)),
  4. Save the changes
  5. Test if the warnings are gone

Let me know how it goes.

roland-d commented 1 year ago

I have now committed this and if there are any further issues they can be reported.