PHP Warning: Undefined variable on PHP 8.1.28
-
Hey team, I am getting the following PHP Warning: Undefined variable on PHP 8.1.28:
PHP Warning: Undefined variable $index in path-to-sitewp-content/plugins/diagnoseo/includes/class-diagnoseo-metatags.php on line 455
PHP Warning: Undefined variable $index in path-to-sitewp-content/plugins/diagnoseo/includes/class-diagnoseo-metatags.php on line 456
PHP Warning: Undefined variable $follow in path-to-sitewp-content/plugins/diagnoseo/includes/class-diagnoseo-metatags.php on line 457
PHP Warning: Undefined variable $follow in path-to-sitewp-content/plugins/diagnoseo/includes/class-diagnoseo-metatags.php on line 458While troubleshooting, I found out that the
Diagnoseo_MetaTags::meta_robots()method was producing the PHP warnings due to the use of undefined variables$indexand$follownot being set when none of theiforelseifconditions were met, leaving these variables undefined when they were later used to set values in the$robotsarray.
As a temporary fix to ensure that$indexand$followare always defined, they were initialized with default values at the beginning of themeta_robotsmethod. Which I’ve added to fix the issue for me:public function meta_robots( $robots ) {
$index = 'noindex'; // Default value
$follow = 'nofollow'; // Default valueI hope this helps, and please let me know if you need any clarification about the issue from my end.
The topic ‘PHP Warning: Undefined variable on PHP 8.1.28’ is closed to new replies.