PHP 8 fatal error
-
The plugin settings page throws a fatal error when running in PHP 8+
Problem: $this->options is sometimes a string instead of an array, causing PHP 8+ to throw a TypeError when trying to access it as an array with [$arg[‘input_name’]].
Why this happens:
– The constructor calls $this->options = get_option(‘ee_options’, $this->defaultOptions)
– If the database option is corrupted or stored as a string instead of array, get_option() returns that string
– The default options array isn’t used if any value exists in the database, even if it’s malformedFix:
387 */
388 public function input_apikey($arg)
389 {
390 - $apikey = $this->options[$arg['input_name']];
390 + // Ensure $this->options is an array and fallback to defaults if not
391 + if (!is_array($this->options)) {
392 + $this->options = $this->defaultOptions;
393 + }
394 +
395 + $apikey = $this->options[$arg['input_name']] ?? '';
396 update_option('ee-apikey', filter_var($apikey, FILTER_SANITIZE_NUMBER_INT));
397 if (empty($apikey) === false) {
398 $apikey = '**********' . substr($apikey, strlen($apikey) - 5, strlen($apikey));It would be nice to have the plugin repo added to github / ElasticEmail so it can be forked, fixed, and pull request send.
The topic ‘PHP 8 fatal error’ is closed to new replies.