spotweb/spotweb

[New issue] utf8_encode() is deprecated

roytje88 opened this issue ยท 19 comments

Describe the bug/issue

  • UTF8_encode() is deprecated at php v8.2.4 (ArchLinux)

Have you searched the internet or Github for an answer?

  • Yes.

To Reproduce
Steps to reproduce the behavior:

  1. Did a fresh git pull
  2. retrieve.php gave error:
    PHP Deprecated: Function utf8_encode() is deprecated in /../spotweb/lib/services/Format/Services_Format_Parsing.php on line 542
    (same on lines 543 and 544)

Expected behavior

  • Retrieve doesn't throw an error.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: ArchLinuxARM (armhf / ARMv7h)
  • Spotweb master branch
  • PHP version 8.2.4-1
  • Spotweb Version [e.g. 1.4.8]
  • Raspberry Pi 4

Additional context
Workaround for me:
Added function below to /../spotweb/lib/services/Format/Services_Format_Parsing.php

function iso8859_1_to_utf8(string $s): string {
    $s .= $s;
    $len = \strlen($s);

    for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
        switch (true) {
            case $s[$i] < "\x80": $s[$j] = $s[$i]; break;
            case $s[$i] < "\xC0": $s[$j] = "\xC2"; $s[++$j] = $s[$i]; break;
            default: $s[$j] = "\xC3"; $s[++$j] = \chr(\ord($s[$i]) - 64); break;
         }
    }
    return substr($s, 0, $j);
 }

And changed following:

        $spot['title'] = iso8859_1_to_utf8($spot['title']);
        $spot['poster'] = iso8859_1_to_utf8($spot['poster']);
        $spot['tag'] = iso8859_1_to_utf8($spot['tag']);

(if this could be the right workaround which also could work for php<8.2.4 please let me know. I'll create a pull request)

UTF8_encode() is also used in:
\vendor\szymach\c-pchart\constants.php
Line 48

Sweepr commented

UTF8_encode() is also used in: \vendor\szymach\c-pchart\constants.php Line 48

Fix for that has been made in 3.0.16 : szymach/c-pchart@7cbaf0d

PHP Deprecated: Creation of dynamic property Services_Retriever_Spots::$_daoFactory is deprecated in /var/www/spotweb/lib/services/Retriever/Services_Retriever_Base.php on line 70

I'm having this issue(utf8_encode() ) too as well as the deprecated message @Fossil01 shared.

with latest master i am getting:

PHP Deprecated: Function utf8_encode() is deprecated in /app/lib/services/Format/Services_Format_Parsing.php on line 542

mesa57 commented

Please use develop branch

I'm using latest development branch, but I still receive this:

PHP Deprecated:  Function utf8_encode() is deprecated in /config/www/vendor/szymach/c-pchart/constants.php on line 48
PHP Deprecated:  Creation of dynamic property Services_Retriever_Spots::$_daoFactory is deprecated in /config/www/lib/services/Retriever/Services_Retriever_Base.php on line 70
PHP Deprecated:  Creation of dynamic property Services_Retriever_Comments::$_daoFactory is deprecated in /config/www/lib/services/Retriever/Services_Retriever_Base.php on line 70
PHP Deprecated:  Creation of dynamic property Services_Retriever_Comments::$_spotDao is deprecated in /config/www/lib/services/Retriever/Services_Retriever_Comments.php on line 16
PHP Deprecated:  Creation of dynamic property Services_Retriever_Comments::$_commentDao is deprecated in /config/www/lib/services/Retriever/Services_Retriever_Comments.php on line 17
PHP Deprecated:  Creation of dynamic property Services_Retriever_Reports::$_daoFactory is deprecated in /config/www/lib/services/Retriever/Services_Retriever_Base.php on line 70
PHP Deprecated:  Creation of dynamic property Services_Retriever_Reports::$_reportDao is deprecated in /config/www/lib/services/Retriever/Services_Retriever_Reports.php on line 13
PHP Deprecated:  Creation of dynamic property Services_Retriever_Reports::$_spotDao is deprecated in /config/www/lib/services/Retriever/Services_Retriever_Reports.php on line 14
mesa57 commented

Please ignore those deprecation notices. But thanks voor reporting.

Sweepr commented

For all "Deprecated" notices, you could add #[\AllowDynamicProperties] at the beginning of each file to silence the warnings.

Except the first one, that one must be updated using composer as it is an external package.

For all "Deprecated" notices, you could add #[\AllowDynamicProperties] at the beginning of each file to silence the warnings.

Except the first one, that one must be updated using composer as it is an external package.

Can you give me an example of how (and where) to add this here?
https://github.com/spotweb/spotweb/blob/develop/vendor/szymach/c-pchart/constants.php

Sweepr commented

PHP Deprecated: Function utf8_encode() is deprecated in /config/www/vendor/szymach/c-pchart/constants.php on line 48 is a different notice.

See: szymach/c-pchart@fbeb077

Ok, simply remove the use of the function works?
What was supposed to be encoded then?

Sweepr commented

Ok, simply remove the use of the function works?
What was supposed to be encoded then?

So it seems, I have no idea, you could ask the creator of the package if you'd like to know.

mesa57 commented

Not tested, but I think if you deselect this, you will get no messages.
afbeelding

Not tested, but I think if you deselect this, you will get no messages. afbeelding

Nope, I already had that disabled.
Still got the error message.

mesa57 commented

Please test the latest from develop branch.

Please test the latest from develop branch.

After I pull the most recent changes php crashes when doing a retrieve.

]$ /usr/bin/php /data/websites/spotweb/html/retrieve.php


SpotWeb v0.68.35.34 on PHP v8.2.9 crashed

Fatal error occured during retrieve:
  Settings needs to be upgraded.



#0 /data/websites/spotweb/html/lib/Bootstrap.php(68): Bootstrap->validate()
#1 /data/websites/spotweb/html/retrieve.php(12): Bootstrap->boot()
#2 {main}

PHP Warning:  Undefined variable $retriever in /data/websites/spotweb/html/retrieve.php on line 296
PHP Fatal error:  Uncaught Error: Call to a member function quit() on null in /data/websites/spotweb/html/retrieve.php:296
Stack trace:
#0 {main}
  thrown in /data/websites/spotweb/html/retrieve.php on line 296
mesa57 commented

You need to execute the bin/upgrade-db.php from the spotweb folder.

You need to execute the bin/upgrade-db.php from the spotweb folder.

Yeah I forgot to this time since normally my script updates spotweb and I did it manually this time. Yeah tat looks better.

]$ /usr/bin/php /data/websites/spotweb/html/retrieve.php
Removing Spot information which is beyond retention period,, done
Last retrieve: 2023-08-03 19:58:52
Retrieving new Spots from server news.eweka.nl...
Appr. Message count: 	4044978
First message number:	2
Last message number:	4044980
Current article number:	4044978

Retrieving 4044978 till 4044981 (parsed: 2, in DB: 1, signed: 1, invalid: 0, rtntn.skip: 0, mod: 1, full: 0, total: 3) in 0.08 seconds
Processed a total of 3 spots
Finished retrieving spots.

Calculating how many spots are new, done.
Last retrieve: 2023-08-03 20:03:12
Retrieving new comments from server news.eweka.nl...
Appr. Message count: 	19982907
First message number:	2
Last message number:	19982909
Current article number:	19982907

Retrieving 19982907 till 19982910, found 3 comments in 0.15 seconds
Processed a total of 3 comments
Finished retrieving comments.

Last retrieve: 2023-08-03 20:03:13
Retrieving new reports from server news.eweka.nl...
Appr. Message count: 	276402
First message number:	2
Last message number:	276404
Current article number:	276404

Processed a total of 0 reports
Finished retrieving reports.

Thanks @mesa57!!