Jump to content

Structural differences with PHP 5.6.3


Butterbean

Recommended Posts

With a prior version of Php, this code was acceptable.

$query = sqlsrv_query($conn, $sql);if ($query === false){  exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)){  	$sumUsageKWH += $row[totalUsage];}sqlsrv_free_stmt($query);?> 

Now, with php 5.6.3, I have to add  a couple of things. 

$query = sqlsrv_query($conn, $sql);if ($query === false){  exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)){  	$sumUsageKWH += $row['totalUsage'];}sqlsrv_free_stmt($query);?> 

due to an error prompt.  Once I make the corrections, I have a new errors all over the place.  Is there a difference in defining a variable with 5.6.3? 

Link to comment
https://forums.phpfreaks.com/topic/293815-structural-differences-with-php-563/
Share on other sites

Here are some errors that were perfectly fine with a previous version of PHP..

 

Notice: Undefined variable: sumUsageKWH in C:\xampp1\htdocs\Utrack\invoice.php on line 71

Notice: Undefined variable: sumUsageWKWi in C:\xampp1\htdocs\Utrack\invoice.php on line 146

Notice: Undefined variable: sumUsageWKWp in C:\xampp1\htdocs\Utrack\invoice.php on line 168

Notice: Use of undefined constant meter_multiplier - assumed 'meter_multiplier' in C:\xampp1\htdocs\Utrack\invoice.php on line303

Notice: Undefined variable: meter_multiplier in C:\xampp1\htdocs\Utrack\invoice.php on line 303

Notice: Use of undefined constant raw_material_price - assumed 'raw_material_price' in C:\xampp1\htdocs\Utrack\invoice.phpon line 303

Notice: Undefined variable: raw_material_price in C:\xampp1\htdocs\Utrack\invoice.php on line 303

Notice: Use of undefined constant basic_charge - assumed 'basic_charge' in C:\xampp1\htdocs\Utrack\invoice.php on line 303

Notice: Undefined variable: basic_charge in C:\xampp1\htdocs\Utrack\invoice.php on line 303

variables definitions have not changed in php since day one. the errors you are seeing were likely always present, but were being hidden by the error_reporting/display_errors settings where the code was being ran at.

 

the undefined variable messages were explained in one of your previous threads, you are referencing a variable that doesn't yet exist. in the case of the += operator, you were shown how to define the variable before the start of the loop to prevent the error.

 

for the Notice: Use of undefined constant meter_multiplier - assumed 'meter_multiplier' type of messages, that's because the code doesn't have the needed single quotes around the associate array index names, making php think you are using a defined constant as the index name, then when it doesn't find a defined constant by that name, it assumes you meant to supply a string, all taking up about 5 times more processing than if the code had been written correctly.

 

both of these problems are because whoever originally wrote the code took short-cuts that saved a little typing (but was probably producing giga-byte size error log files.) the way to fix the errors is to do the work now that the original programmer left out of properly initializing variables and of putting quotes around things that are strings.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.