-1

I'm completely lost with an "500 internal server error". Yesterday I updated to PHP 7.1.2 and then there were a lot of errors.

I solved them almost all except for this strange coding error. When trying to find the problem I echoed some output to the screen. And this is what happens:

for($iRecordNumber=0;$iRecordNumber==$iTotalAssignments;$iRecordNumber++){
    $iNextRecordNumber = $iRecordNumber+1;        
    echo $iNextRecordNumber;
    echo $aAssignments[$iRecordNumber][2];
    echo $aAssignments[$iNextRecordNumber][2];
}

With this code I get the "500-error".

When I comment out the line with echo $aAssignments[$iNextRecordNumber][2]; the error is gone and it does what it should do. Showing me a record from the nested array $aAssignments(PDO query).

for($iRecordNumber=0;$iRecordNumber==$iTotalAssignments;$iRecordNumber++){
    $iNextRecordNumber = $iRecordNumber+1;        
    echo $iNextRecordNumber;
    echo $aAssignments[$iRecordNumber][2];
    // echo $aAssignments[$iNextRecordNumber][2];
}

I looked through the Backward compatabilty list but did not find anything.

And the tool codechecker says it's good too.

I dont know how this is possible.

What can I do to find an answer? Are there any programs or code checkers to check for more php 7 errors in my code. I have several php sites running and I do not want to check all code manually for errors.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
jdkos
  • 7
  • 8
  • 1
    I don't get the logic. It looks like that `for` loop will be executed only once, and only if `$iTotalAssignments` is 0. Maybe you meant to use `<` instead of `==`. – laurent Mar 02 '17 at 13:30
  • 1
    besides what @this.lau_ said. check out your server log , or even enable your php displaying errors , `ini_set("display_errors", 1);error_reporting(E_ALL);` – hassan Mar 02 '17 at 13:35
  • @this.lau, you where correct about "<" but the post did not except the "<" and left the rest out of the message. and HassanAhmed Ini_set didn't report the error. Instead I used the new try{ } catch(error $e){ echo $e->getmessage();} – jdkos Mar 02 '17 at 16:05
  • Possible duplicate of [PHP's white screen of death](http://stackoverflow.com/questions/1475297/phps-white-screen-of-death) – Your Common Sense Mar 02 '17 at 16:25

2 Answers2

0

I think $aAssignments[$iNextRecordNumber][2] is not always set. You could replace:

echo $aAssignments[$iNextRecordNumber][2];

By:

echo $aAssignments[$iNextRecordNumber][2]?? '';

I hope it could help.

rap-2-h
  • 30,204
  • 37
  • 167
  • 263
-1

In PHP 7 is the error handling completly revised. A fatal error other errors no longer stops the script. To find these kind of errors, use the new error() method in the try and catch class. For example:

try{
   code to test on errors
} catch(error $eCatchedError) { 
    echo get_class($eCatchedError)."<br>".$eCatchedError->getLine()."<br>".$eCatchedError->getFile()."<br>".$eCatchedError->getMessage();    
} // End try and catch

By this way you get an more elegant way of showing an error (with css and everything)

jdkos
  • 7
  • 8