Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New issue] utf8_encode() is deprecated #812

Closed
roytje88 opened this issue Mar 25, 2023 · 19 comments
Closed

[New issue] utf8_encode() is deprecated #812

roytje88 opened this issue Mar 25, 2023 · 19 comments

Comments

@roytje88
Copy link

roytje88 commented Mar 25, 2023

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)

@stfrbrntyu
Copy link

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

@Sweepr
Copy link
Collaborator

Sweepr commented Mar 26, 2023

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

mesa57 added a commit that referenced this issue Mar 26, 2023
@Fossil01
Copy link

Fossil01 commented Apr 5, 2023

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

@Hydranet
Copy link

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

@rayures
Copy link

rayures commented Jun 29, 2023

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
Copy link
Collaborator

mesa57 commented Jun 29, 2023

Please use develop branch

@rogierlommers
Copy link

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
Copy link
Collaborator

mesa57 commented Jul 13, 2023

Please ignore those deprecation notices. But thanks voor reporting.

@Sweepr
Copy link
Collaborator

Sweepr commented Jul 15, 2023

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.

@rogierlommers
Copy link

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
Copy link
Collaborator

Sweepr commented Jul 15, 2023

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

@rogierlommers
Copy link

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

@Sweepr
Copy link
Collaborator

Sweepr commented Jul 15, 2023

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
Copy link
Collaborator

mesa57 commented Jul 15, 2023

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

@rogierlommers
Copy link

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 pushed a commit to mesa57/spotweb that referenced this issue Aug 3, 2023
- Revamped date formatting and localization
- Settings updated to 0.35
mesa57 added a commit that referenced this issue Aug 3, 2023
Amend php 8.2 deprecation issues (issue #812)
@mesa57
Copy link
Collaborator

mesa57 commented Aug 3, 2023

Please test the latest from develop branch.

@Hydranet
Copy link

Hydranet commented Aug 3, 2023

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
Copy link
Collaborator

mesa57 commented Aug 3, 2023

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

@Hydranet
Copy link

Hydranet commented Aug 3, 2023

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!!

@mesa57 mesa57 closed this as completed Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants