PHP Warning: Undefined array key “state” in actions.php on line 29
-
Hi FluentSMTP team,
I’m using the latest version of FluentSMTP on my WordPress site and I noticed a PHP warning being logged repeatedly:
PHP Warning: Undefined array key "state" in /wp-content/plugins/fluent-smtp/app/Hooks/actions.php on line 29After checking the code, it seems the warning comes from this line:
$state = $_REQUEST['state'];This line is located inside a
permission_callbackfunction in therest_api_inithook for the/fluent-smtp/outlook_callback/endpoint. The warning occurs when thestateparameter is not present in the request, which causes PHP to throw a warning due to accessing an undefined array key.I’m running PHP version 8.2.21 (64-bit support), where such access without checking existence triggers a warning.
To improve compatibility with PHP 8+, I suggest modifying the line to:
$state = $_REQUEST['state'] ?? null;Or alternatively:
$state = isset($_REQUEST['state']) ? $_REQUEST['state'] : null;This would prevent the warning while preserving the intended OAuth security check.
Thanks in advance for looking into this!
Best regards,
Ângelo Antunes
The topic ‘PHP Warning: Undefined array key “state” in actions.php on line 29’ is closed to new replies.