PHP Warning: Use of Undefined Constant
-
I noticed the following PHP warnings (PHP 7.3) each time I visited the Widgets Page in Admin, even though I’m not using the List Areas Widget:
Use of undefined constant city - assumed 'city' (this will throw an Error in a future version of PHP) in /home/username/public_html/wp-content/plugins/dsidxpress/widget-list-areas.php on line 106 Use of undefined constant community - assumed 'community' (this will throw an Error in a future version of PHP) in /home/username/public_html/wp-content/plugins/dsidxpress/widget-list-areas.php on line 107 Use of undefined constant tract - assumed 'tract' (this will throw an Error in a future version of PHP) in /home/username/public_html/wp-content/plugins/dsidxpress/widget-list-areas.php on line 108 Use of undefined constant zip - assumed 'zip' (this will throw an Error in a future version of PHP) in /home/username/public_html/wp-content/plugins/dsidxpress/widget-list-areas.php on line 109
On lines 106-109, it appears the developers left out the quotes for city, community, tract, and zip that are going to be required in future versions of PHP and trigger the warnings:
<option value="city" {$selectedAreaType[city]}>Cities</option> <option value="community" {$selectedAreaType[community]}>Communities</option> <option value="tract" {$selectedAreaType[tract]}>Tracts</option> <option value="zip" {$selectedAreaType[zip]}>Zip Codes</option>
So to prevent the warning piling up in your error logs, you can just add the quotes:
<option value="city" {$selectedAreaType['city']}>Cities</option> <option value="community" {$selectedAreaType['community']}>Communities</option> <option value="tract" {$selectedAreaType['tract']}>Tracts</option> <option value="zip" {$selectedAreaType['zip']}>Zip Codes</option>
A similar PHP warning occurs in the file locations.php, where searchSetupID and type, the indices for two of the array elements aren’t quoted:
searchSetupID => $options["SearchSetupID"], type => $_REQUEST["type"]
That PHP warning isn’t triggered unless you use the zip codes option in the List Areas Widget. You can prevent the warning by quoting the indices:
"searchSetupID" => $options["SearchSetupID"], "type" => $_REQUEST["type"]
I know these won’t interfere with the operation of the plugin, but who wants a bunch of PHP warnings in their error logs?
- The topic ‘PHP Warning: Use of Undefined Constant’ is closed to new replies.