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

PHP 8.1 error Profile view articles #911

Closed
Bopske opened this issue May 13, 2022 · 4 comments · Fixed by #912
Closed

PHP 8.1 error Profile view articles #911

Bopske opened this issue May 13, 2022 · 4 comments · Fixed by #912
Milestone

Comments

@Bopske
Copy link
Contributor

Bopske commented May 13, 2022

Access the my articles page from the profile:

https://localhost/vanilla/index.php?action=profile;area=tparticles;u=3
C:/xampp/htdocs/vanilla/Sources/TPSubs.php (Line 2808)

Notice
: explode(): Passing null to parameter #2 ($string) of type string is deprecated in
C:\xampp\htdocs\vanilla\Sources\TPSubs.php
on line
2808

code

2804: if($smcFunc'db_num_rows' > 0){
2805: while($row = $smcFunc'db_fetch_assoc') {
2806: $rat = array();
2807: $rating_votes = 0;
==>2808: $rat = explode(',', $row['rating']);
2809: $rating_votes = count($rat);
2810: if($row['rating'] == '') {
2811: $rating_votes = 0;
2812: }
@Bopske Bopske added this to the 2.2.3 milestone May 13, 2022
@Bopske
Copy link
Contributor Author

Bopske commented May 13, 2022

solution?

$rat = explode(',', (string)$row['rating']);

or

$rat = explode(',', $row['rating'] ?? ' ');

which one is better?
note: must m=be supported from PHP7.0.0 onwards

@tinoest
Copy link
Contributor

tinoest commented May 13, 2022

$rat = !is_null($row['rating']) ? explode(',', $row['rating']) : 0;

@Bopske
Copy link
Contributor Author

Bopske commented May 13, 2022

$rat = !is_null($row['rating']) ? explode(',', $row['rating']) : 0;

I used this,

$rat = explode(',', $row['rating'] ?? ' ');

?? is supported from PHP7.0.
Do you see any issues with that?

@tinoest
Copy link
Contributor

tinoest commented May 13, 2022

I personally can’t see an issue today, if PHP decide to throw a error on an empty string it will.

I’ve done it the way I put in other places so consistency should be we do one or the other. I personally don’t like having conditionals inside functions as it can be harder to track down an error, but functionally your way will work.

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

Successfully merging a pull request may close this issue.

2 participants