Texan78 Posted April 2, 2014 Share Posted April 2, 2014 It appears my host has done some upgrades to the latest PHP. Since this update some of my scripts are throwing errors. I am not sure why these errors are being generated as it looks ok to me. I can turn error reporting off and they go away but I would rather do it right and fix the error. The errors don't cause the script to not work, just throws the annoying error. Maybe I just need another set of eyes and someone with a little more experience than I have as the variable looks to be defined unless I am missing something. Here is the page http://www.mesquiteweather.net/wxspotter.php Here is where it says the error starts $noStormMessage .= "<table style='{$noMessageStyle}' cellpadding='0' cellspacing='0'>\n"; $noStormMessage .= "<tbody>\n"; $noStormMessage .= " <tr><td style='{$td1Style}'>LIVE STORM SPOTTER REPORTS</td></tr>\n"; $noStormMessage .= " <tr><td style='{$td4Style}'>There are currently no storm reports</td></tr>\n"; $noStormMessage .= "</tbody>\n"; $noStormMessage .= "</table>\n"; $noStormMessage .= $afterTable; Here is the full script <?php ####################################################################################### # # SPOTTER NETWORK STORM REPORTS # version 1.00 # # This program is free and no license is required. # # # mesquiteweather.net # ####################################################################################### //// SETTINGS //// //// SETTINGS //// $bkgColor = '#d4d4d4'; // Background color Examples: "gray" "#CCC" "#CCCCCC" $bc = '#EEEEEE'; // Background color of table cells $dtColor = '#FFF'; // Date & time color Examples: "#FC0" "#FFCC00" "white" $width = '100%'; // Set the width of the report tables //// END OF SETTINGS //// ####################################################################################### ini_set('display_errors','1'); ## Start Configurable data ## //Set path to data file $data = "http://www.spotternetwork.org/data.php"; ## End Configurable data ## // overrides from the Carter Lake Settings.php file (if applicable) global $SITE; if(isset($SITE['cacheFileDir'])) {$cacheFileDir = $SITE['cacheFileDir']; } if (isset($SITE['imagesDir'])) {$imagesDir = $SITE['imagesDir'];} if(isset ($SITE['tz'])) {$ourTZ = $SITE['tz'];} if(!function_exists('date_default_timezone_set')) { putenv("TZ=" . $ourTZ); } else { date_default_timezone_set("$ourTZ"); } // get path info & protect for cross-site scripting vulnerability $sri = ($_SERVER['REQUEST_URI']) ? str_replace('#SA', '', htmlspecialchars(strip_tags($_SERVER['REQUEST_URI']))) : ''; // set borders $bbrdr = 'border-bottom:thin solid black'; // bottom $lbrdr = 'border-left:thin solid black'; // left $rbrdr = 'border-right:thin solid black'; // right $tbrdr = 'border-top:thin solid black'; // top $sbrdr = 'border-right:thin solid black; '. 'border-left:thin solid black'; // side //Define table to display after each storm report $afterTable = "<table style='margin-bottom: 5px;' border='0' cellpadding='0' cellspacing='0' width='100%'><tbody><tr><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td><td class='shadow-mid' width='100%'><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td></tr><tbody></table>\n"; // Let's assign the table some styles $noMessageStyle = "width:{$width}; text-align:center; margin:0px auto; background-color:{$bkgColor};"; $td1Style = "{$tbrdr};{$sbrdr}; padding:2px 0px 2px 6px; background-image:url({$imagesDir}headerbgd2.gif); color:{$dtColor};"; $td2Style = "{$sbrdr}; padding:6px 0px 0px 6px;"; $td3Style = "{$sbrdr}; line-height:5px;"; $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px;"; //Set message to display if there were not report $noStormMessage .= "<table style='{$noMessageStyle}' cellpadding='0' cellspacing='0'>\n"; $noStormMessage .= "<tbody>\n"; $noStormMessage .= " <tr><td style='{$td1Style}'>LIVE STORM SPOTTER REPORTS</td></tr>\n"; $noStormMessage .= " <tr><td style='{$td4Style}'>There are currently no storm reports</td></tr>\n"; $noStormMessage .= "</tbody>\n"; $noStormMessage .= "</table>\n"; $noStormMessage .= $afterTable; $xml = simplexml_load_file($data); //Set initial output to false $tData = false; foreach($xml->report as $report) { $date = $report['stamp']; $time = strtotime($date.'UTC'); $dateInLocal = date("D g:i a", $time); $narrative = $report['narrative']; $loc = $report['city1']; $tz = $report['tz']; $stormType = 'Unknown'; foreach($report->attributes() as $typeKey => $id) { if($id == 1) { if(array_key_exists($typeKey, $stormTypesAry)) { $stormType = $stormTypesAry[$typeKey]; } break; } } $stormTypesAry = array( 'tornado' => 'Tornado', 'funnelcloud' => 'Funnel Cloud', 'wallcloud' => 'Wall Cloud', 'rotation' => 'Rotation', 'hail' => 'Hail', 'wind' => 'Wind', 'flood' => 'Flood', 'flashflood' => 'Flash Flood' ); $stormTypesAry['tornado'] = array('name' => 'Tornado', 'color' => 'rgba(255, 0, 0, 0.2)'); $stormTypesAry['funnelcloud'] = array('name' => 'Funnel Cloud', 'color' => 'rgba(255, 100, 0, 0.2)'); $stormTypesAry['wallcloud'] = array('name' => 'Wall Cloud', 'color' => 'rgba(255, 255, 0, 0.2)'); $stormTypesAry['rotation'] = array('name' => 'Rotation', 'color' => 'rgba(255, 228, 181, 0.2)'); $stormTypesAry['hail'] = array('name' => 'Hail', 'color' => 'rgba(160, 0, 255, 0.2)'); $stormTypesAry['wind'] = array('name' => 'Wind', 'color' => 'rgba(235, 235, 250, 1.0)'); $stormTypesAry['flood'] = array('name' => 'Flood', 'color' => 'rgba(0, 255, 0, 0.2)'); $stormTypesAry['flashflood'] = array('name' => 'Flash Flood', 'color' => 'rgba(0, 255, 50, 0.2)'); $stormTypesAry['Other'] = array('name' => 'Other', 'color' => 'rgba(0, 255, 50, 0.2)'); $reportColor = ''; // get the stormType and reportColor using the $typeKey $stormType = $stormTypesAry[$typeKey]['name']; $reportColor = $stormTypesAry[$typeKey]['color']; // this line takes the place of all the switch/case logic // Set table style $tableStyle = "width: 100%; margin:0px auto; background-color:{$bkgColor};"; $td1Style = "{$tbrdr};{$sbrdr}; padding:2px 0px 2px 6px; background-image:url({$imagesDir}headerbgd2.gif); color:{$dtColor};"; $td2Style = "{$sbrdr}; padding:6px 0px 0px 6px; background-color:{$reportColor};"; $td3Style = "{$sbrdr}; line-height:5px; background-color:{$reportColor};"; $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$reportColor};"; // construct data for table display $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n"; $tData .= "<tbody>\n"; $tData .= " <tr><td style='{$td1Style}'><b>{$stormType}</b></td></tr>\n"; $tData .= " <tr>\n"; $tData .= " <td style='{$td2Style}'>Reported: <b>{$dateInLocal}</b> - </b>Location: <b>{$loc}</b></td>\n"; $tData .= " </tr>\n"; $tData .= " <tr><td style='{$td3Style}'> </td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'>Description: <b>{$narrative}</b></td></tr>\n"; $tData .= "</tbody>\n"; $tData .= "</table>\n"; $tData .= $afterTable; } //If no storms were in the source, set no storm message if(!$tData) { $tData = $noStormMessage; } echo $tData; ?> Quote Link to comment https://forums.phpfreaks.com/topic/287481-undefined-errors-since-host-php-upgrade/ Share on other sites More sharing options...
boompa Posted April 2, 2014 Share Posted April 2, 2014 Chances are these errors have always been there, but the update revealed them to you where they were hidden before. The first is because of this line: $noStormMessage .= "<table style='{$noMessageStyle}' cellpadding='0' cellspacing='0'>\n"; That's saying "concatenate the right side of the = with the existing string in the $noStormMessage variable". Problem is, there *is* no existing variable called $noStormMessage. Solution to that is not to use .= in that line, but just =. The other two are related and self-explanatory. You have no array variable defined called $stormTypesAry until *after* you're trying to use it. Move the definition of this variable before the attempt to use it. Quote Link to comment https://forums.phpfreaks.com/topic/287481-undefined-errors-since-host-php-upgrade/#findComment-1474755 Share on other sites More sharing options...
Texan78 Posted April 3, 2014 Author Share Posted April 3, 2014 This shouldn't have been hidden before since e_reporting was on. They didn't become errors until the update. $noStormMessage is defined that is the thing. If that is the problem then $tData would also be showing as undefined. changing .= to =. does nothing. $stormTypesAry is clearly defined before it is used if you look closely. I am not sure what you're trying to say. Quote Link to comment https://forums.phpfreaks.com/topic/287481-undefined-errors-since-host-php-upgrade/#findComment-1474757 Share on other sites More sharing options...
QuickOldCar Posted April 3, 2014 Share Posted April 3, 2014 Simply put, an array should exist before you try to access it <?php ####################################################################################### # # SPOTTER NETWORK STORM REPORTS # version 1.00 # # This program is free and no license is required. # # # mesquiteweather.net # ####################################################################################### //// SETTINGS //// //// SETTINGS //// $bkgColor = '#d4d4d4'; // Background color Examples: "gray" "#CCC" "#CCCCCC" $bc = '#EEEEEE'; // Background color of table cells $dtColor = '#FFF'; // Date & time color Examples: "#FC0" "#FFCC00" "white" $width = '100%'; // Set the width of the report tables //// END OF SETTINGS //// ####################################################################################### ini_set('display_errors','1'); ## Start Configurable data ## //Set path to data file $data = "http://www.spotternetwork.org/data.php"; ## End Configurable data ## // overrides from the Carter Lake Settings.php file (if applicable) global $SITE; if(isset($SITE['cacheFileDir'])) {$cacheFileDir = $SITE['cacheFileDir']; } if (isset($SITE['imagesDir'])) {$imagesDir = $SITE['imagesDir'];} if(isset ($SITE['tz'])) {$ourTZ = $SITE['tz'];} if(!function_exists('date_default_timezone_set')) { putenv("TZ=" . $ourTZ); } else { date_default_timezone_set("$ourTZ"); } // get path info & protect for cross-site scripting vulnerability $sri = ($_SERVER['REQUEST_URI']) ? str_replace('#SA', '', htmlspecialchars(strip_tags($_SERVER['REQUEST_URI']))) : ''; // set borders $bbrdr = 'border-bottom:thin solid black'; // bottom $lbrdr = 'border-left:thin solid black'; // left $rbrdr = 'border-right:thin solid black'; // right $tbrdr = 'border-top:thin solid black'; // top $sbrdr = 'border-right:thin solid black; '. 'border-left:thin solid black'; // side //Define table to display after each storm report $afterTable = "<table style='margin-bottom: 5px;' border='0' cellpadding='0' cellspacing='0' width='100%'><tbody><tr><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td><td class='shadow-mid' width='100%'><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td></tr><tbody></table>\n"; // Let's assign the table some styles $noMessageStyle = "width:{$width}; text-align:center; margin:0px auto; background-color:{$bkgColor};"; $td1Style = "{$tbrdr};{$sbrdr}; padding:2px 0px 2px 6px; background-image:url({$imagesDir}headerbgd2.gif); color:{$dtColor};"; $td2Style = "{$sbrdr}; padding:6px 0px 0px 6px;"; $td3Style = "{$sbrdr}; line-height:5px;"; $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px;"; //Set message to display if there were not report $noStormMessage = "<table style='{$noMessageStyle}' cellpadding='0' cellspacing='0'>\n"; $noStormMessage .= "<tbody>\n"; $noStormMessage .= " <tr><td style='{$td1Style}'>LIVE STORM SPOTTER REPORTS</td></tr>\n"; $noStormMessage .= " <tr><td style='{$td4Style}'>There are currently no storm reports</td></tr>\n"; $noStormMessage .= "</tbody>\n"; $noStormMessage .= "</table>\n"; $noStormMessage .= $afterTable; $xml = simplexml_load_file($data); //Set initial output to false $tData = false; foreach($xml->report as $report) { $date = $report['stamp']; $time = strtotime($date.'UTC'); $dateInLocal = date("D g:i a", $time); $narrative = $report['narrative']; $loc = $report['city1']; $tz = $report['tz']; $stormType = 'Unknown'; $stormTypesAry = array( 'tornado' => 'Tornado', 'funnelcloud' => 'Funnel Cloud', 'wallcloud' => 'Wall Cloud', 'rotation' => 'Rotation', 'hail' => 'Hail', 'wind' => 'Wind', 'flood' => 'Flood', 'flashflood' => 'Flash Flood' ); foreach($report->attributes() as $typeKey => $id) { if($id == 1) { if(array_key_exists($typeKey, $stormTypesAry)) { $stormType = $stormTypesAry[$typeKey]; } break; } } $stormTypesAry['tornado'] = array('name' => 'Tornado', 'color' => 'rgba(255, 0, 0, 0.2)'); $stormTypesAry['funnelcloud'] = array('name' => 'Funnel Cloud', 'color' => 'rgba(255, 100, 0, 0.2)'); $stormTypesAry['wallcloud'] = array('name' => 'Wall Cloud', 'color' => 'rgba(255, 255, 0, 0.2)'); $stormTypesAry['rotation'] = array('name' => 'Rotation', 'color' => 'rgba(255, 228, 181, 0.2)'); $stormTypesAry['hail'] = array('name' => 'Hail', 'color' => 'rgba(160, 0, 255, 0.2)'); $stormTypesAry['wind'] = array('name' => 'Wind', 'color' => 'rgba(235, 235, 250, 1.0)'); $stormTypesAry['flood'] = array('name' => 'Flood', 'color' => 'rgba(0, 255, 0, 0.2)'); $stormTypesAry['flashflood'] = array('name' => 'Flash Flood', 'color' => 'rgba(0, 255, 50, 0.2)'); $stormTypesAry['Other'] = array('name' => 'Other', 'color' => 'rgba(0, 255, 50, 0.2)'); $reportColor = ''; // get the stormType and reportColor using the $typeKey $stormType = $stormTypesAry[$typeKey]['name']; $reportColor = $stormTypesAry[$typeKey]['color']; // this line takes the place of all the switch/case logic // Set table style $tableStyle = "width: 100%; margin:0px auto; background-color:{$bkgColor};"; $td1Style = "{$tbrdr};{$sbrdr}; padding:2px 0px 2px 6px; background-image:url({$imagesDir}headerbgd2.gif); color:{$dtColor};"; $td2Style = "{$sbrdr}; padding:6px 0px 0px 6px; background-color:{$reportColor};"; $td3Style = "{$sbrdr}; line-height:5px; background-color:{$reportColor};"; $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$reportColor};"; // construct data for table display $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n"; $tData .= "<tbody>\n"; $tData .= " <tr><td style='{$td1Style}'><b>{$stormType}</b></td></tr>\n"; $tData .= " <tr>\n"; $tData .= " <td style='{$td2Style}'>Reported: <b>{$dateInLocal}</b> - </b>Location: <b>{$loc}</b></td>\n"; $tData .= " </tr>\n"; $tData .= " <tr><td style='{$td3Style}'> </td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'>Description: <b>{$narrative}</b></td></tr>\n"; $tData .= "</tbody>\n"; $tData .= "</table>\n"; $tData .= $afterTable; } //If no storms were in the source, set no storm message if(!$tData) { $tData = $noStormMessage; } echo $tData; ?> Quote Link to comment https://forums.phpfreaks.com/topic/287481-undefined-errors-since-host-php-upgrade/#findComment-1474762 Share on other sites More sharing options...
cyberRobot Posted April 3, 2014 Share Posted April 3, 2014 This shouldn't have been hidden before since e_reporting was on. They didn't become errors until the update. Note that there are multiple levels of error reporting. Perhaps the following will help: http://www.php.net/manual/en/function.error-reporting.php Also note that there's a setting which determines whether or not those errors are displayed to the screen: http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors Quote Link to comment https://forums.phpfreaks.com/topic/287481-undefined-errors-since-host-php-upgrade/#findComment-1474797 Share on other sites More sharing options...
cyberRobot Posted April 3, 2014 Share Posted April 3, 2014 $noStormMessage is defined that is the thing. If that is the problem then $tData would also be showing as undefined. changing .= to =. does nothing. It looks like you defined $tData here: //... //Set initial output to false $tData = false; foreach($xml->report as $report) //... Quote Link to comment https://forums.phpfreaks.com/topic/287481-undefined-errors-since-host-php-upgrade/#findComment-1474800 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.