Jump to content

Structural differences with PHP 5.6.3


Butterbean
Go to solution Solved by mac_gyver,

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? 

Edited by Butterbean
Link to comment
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

Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.