Skip to content

php 8.1 warning - Parser/Conditional/BooleanExpression.php, line 130 #3259

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

Closed
jcogs-design opened this issue Apr 11, 2023 · 7 comments · Fixed by #3416
Closed

php 8.1 warning - Parser/Conditional/BooleanExpression.php, line 130 #3259

jcogs-design opened this issue Apr 11, 2023 · 7 comments · Fixed by #3416

Comments

@jcogs-design
Copy link
Contributor

Front-end error, php 8.1.16 / EE 7.2.14

Error Messages


Warning
foreach() argument must be of type array|object, null given

ee/ExpressionEngine/Library/Parser/Conditional/BooleanExpression.php, line 130

    Severity: E_WARNING
@intoeetive
Copy link
Contributor

@jcogs-design any ideas which specific conditional in template is causing that?

@jcogs-design
Copy link
Contributor Author

It appears to be this one

{if '{iso_code}' != 'en-gb'}<option value='{iso_code}' {if get_post:language == iso_code}selected{/if}>{name}</option>{/if}

@intoeetive
Copy link
Contributor

Is iso_code coming from custom field? Or an add-on?
Also, get_post: - is that Mo'Variables or something similar?

@jcogs-design
Copy link
Contributor Author

iso_code is coming from an addon (jcogs_mts)
get_post: is coming from Mo'Variables
The warning appears if the get_post variable is not set (i.e. if page url is https://add-on-dev-7.ddev.site/home/mts_tester you get the warning, if it is https://add-on-dev-7.ddev.site/home/mts_tester?language=fr you don't.
HTH

@intoeetive
Copy link
Contributor

I wasn't able to replicate it, but my guess would be that you see it in case where both get_post:language and iso_code are not defined or empty.

Can you add this code around line 53, right in the beginning of public function evaluate():

if (empty($this->tokens)) {
return true;
}

I am not sure whether that should evalulate to true or false though - on the one hand, it's empty-to-empty comparison (true), on the other hand - both values are not set (false?)

@jcogs-design
Copy link
Contributor Author

I'll try that, but just for the lols this also works (tested) - insert before line 130 in BooleanExpression.php

if(is_null($tokens)) {
    return $output;
}

@intoeetive
Copy link
Contributor

@jcogs-design when you get time, can you give a try to the solution provided in the PR referenced here? I think it's a bit better solution because it's happening earlier in the code, but I don't have a way to test it

bryannielsen added a commit that referenced this issue Jun 8, 2023
…sion-null

Resolved #3259 where certain coditionals in templates could generate PHP warning
matthewjohns0n added a commit that referenced this issue Jun 12, 2023
…sion-null

Resolved #3259 where certain coditionals in templates could generate PHP warning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants