|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-07-08 16:23 UTC] buschmann at nidsa dot net
Description:
------------
During testing our application for compatibility with php 8 one script stopped suddenly and the resulting web page was incomplete.
This occured when loading the empty web page without retrieving the central data from the database.
The stop occurs at the following lines of code (the original code):
...
for($i=0;$i<=7;$i++){
@$fSOrder=pg_fetch_assoc($rSOrder);
if($fSOrder['od_distribution']==2){
...
This code has worked on all the version 7.x.y until 7.4.8 even if it misses error-handling.
The query to get a valid $rSOrder with pg_query has not been called/executed, so $rSOrder is not existent at this point of the script.
($rSOrder etc. is declared global in a function for executing the query:
function searchOrder(){
global $fSOrder,$rSOrder,$book,$iden,$style,$season,$file,$only;
...
The original application developers knew that at this point there could be an error by using the not existing $rSOrder and included the @ to suppress the error message (not introduced/changed by me).
When using php8 (already tested on php8 alpha 2) the script terminates with a last error message pointing to the line of pg_fetch_assoc:
08-Jul-2020 16:35:20 Europe/Berlin] PHP Warning: Undefined variable $rSOrder in N:\cpsdev\cps\cps_pg\AltaPedido.php on line 2390
The script terminates processing without any fatal error/crash and sends the incomplete web page to apache/browser.
On the same machine and the same source tree php 7.4.8 logs the same error but continues and completes the web page.
The problem remains when removing error reporting by deleting the @.
Environment:
- Windows server 2019 64bit Standard in a VM under HyperV
- Apache 2.43 64bit from apachelounge
- php 8 alpha2 64bit thread safe from php.net QA download
- php loaded as a module with php_module
- JIT is on for php8 (not sure if it is really used)
- opcache is enabled
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 18:00:01 2025 UTC |
The point is that pg_fetch_assoc($rSOrder) is called while $rSOrder is undefined. This is supposed to throw a TypeError in PHP 8. This TypeError is apparently caught by your script (maybe by set_error_handler() or set_exception_handler()). At least for debugging purposes, you could rewrite @$fSOrder=pg_fetch_assoc($rSOrder); to $fsOrder = isset($rSOrder) ? pg_fetch_assoc($rSOrder) : []; or so.I have condensed the original script to a short version (even missing the connection to the database). This reproduces the same error (abrupt script termination): <?php session_start (); function searchOrder(){ global $fSOrder,$rSOrder,$book,$iden,$style,$season,$file,$only; echo 'inside searchOrder'; } ?> <!DOCTYPE html> <html> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td><h2 style="margin-left:4px;">BOX</h2></td> <td><input type="text" name="Txt_SizeA1AP" class="CuadroTextoOtro" style="width:25px;" disabled readonly="yes" value=""/></td> <td><input type="text" name="Txt_SizeA2AP" class="CuadroTextoOtro" style="width:25px;" disabled readonly="yes" value=""/></td> <td><input type="text" name="Txt_SizeA3AP" class="CuadroTextoOtro" style="width:25px;" disabled readonly="yes" value=""/></td> <td><input type="text" name="Txt_SizeA4AP" class="CuadroTextoOtro" style="width:25px;" disabled readonly="yes" value=""/></td> <td><input type="text" name="Txt_SizeA5AP" class="CuadroTextoOtro" style="width:25px;" disabled readonly="yes" value=""/></td> <td><input type="text" name="Txt_SizeA6AP" class="CuadroTextoOtro" style="width:25px;" disabled readonly="yes" value=""/></td> <td><input type="text" name="Txt_SizeA7AP" class="CuadroTextoOtro" style="width:25px;" disabled readonly="yes" value=""/></td> <td><input type="text" name="Txt_SizeA8AP" class="CuadroTextoOtro" style="width:25px;" disabled readonly="yes" value=""/></td> <td><input type="text" name="Txt_SizeA9AP" class="CuadroTextoOtro" style="width:25px;" disabled readonly="yes" value=""/></td> <td><input type="text" name="Txt_SizeA10AP" class="CuadroTextoOtro" style="width:25px;" disabled readonly="yes" value=""/></td> <td><input type="text" name="Txt_SizeA11AP" class="CuadroTextoOtro" style="width:25px;" disabled readonly="yes" value=""/></td> <td><input type="text" name="Txt_SizeA12AP" class="CuadroTextoOtro" style="width:25px;" disabled readonly="yes" value=""/></td> <td><h2 style="margin-left:2px;">TOTAL</h2></td> </tr> <?php for($i=0;$i<=7;$i++){ //HB @$fSOrder=pg_fetch_assoc($rSOrder); $fSOrder=pg_fetch_assoc($rSOrder); echo "<tr>"; echo "<td><input type='text' name=Txt_BoxAAP$i class='TextoSubFicha' style='width:30px; background-color:#FFFFFF; font-weight:bold;' onBlur=\"calPairs('box',this.name,$i);\"/><input type='hidden' name='Txt_id_a$i' value='0'/></td>"; echo "<td><input type='text' name=Txt_CantSizeA1AP$i class='CuadroTallas' onChange=\"calPairs('assorted',this.name,$i)\" disabled/></td>"; echo "<td><input type='text' name=Txt_CantSizeA2AP$i class='CuadroTallas' onChange=\"calPairs('assorted',this.name,$i)\" disabled/></td>"; echo "<td><input type='text' name=Txt_CantSizeA3AP$i class='CuadroTallas' onChange=\"calPairs('assorted',this.name,$i)\" disabled/></td>"; echo "<td><input type='text' name=Txt_CantSizeA4AP$i class='CuadroTallas' onChange=\"calPairs('assorted',this.name,$i)\" disabled/></td>"; echo "<td><input type='text' name=Txt_CantSizeA5AP$i class='CuadroTallas' onChange=\"calPairs('assorted',this.name,$i)\" disabled/></td>"; echo "<td><input type='text' name=Txt_CantSizeA6AP$i class='CuadroTallas' onChange=\"calPairs('assorted',this.name,$i)\" disabled/></td>"; echo "<td><input type='text' name=Txt_CantSizeA7AP$i class='CuadroTallas' onChange=\"calPairs('assorted',this.name,$i)\" disabled/></td>"; echo "<td><input type='text' name=Txt_CantSizeA8AP$i class='CuadroTallas' onChange=\"calPairs('assorted',this.name,$i)\" disabled/></td>"; echo "<td><input type='text' name=Txt_CantSizeA9AP$i class='CuadroTallas' onChange=\"calPairs('assorted',this.name,$i)\" disabled/></td>"; echo "<td><input type='text' name=Txt_CantSizeA10AP$i class='CuadroTallas' onChange=\"calPairs('assorted',this.name,$i)\" disabled/></td>"; echo "<td><input type='text' name=Txt_CantSizeA11AP$i class='CuadroTallas' onChange=\"calPairs('assorted',this.name,$i)\" disabled/></td>"; echo "<td><input type='text' name=Txt_CantSizeA12AP$i class='CuadroTallas' onChange=\"calPairs('assorted',this.name,$i)\" disabled/></td>"; echo "<td><input type='text' name=Txt_TotalAAP$i class='TextoSubFicha' style='width:35px; background-color:#FFFFFF; font-weight:bold;' readonly='yes'/></td>"; echo "</tr>"; } echo 'past for loop'; ?> </table> </html>Your script produces: Warning: Undefined variable $rSOrder in /home/nikic/php/php-src/t036.php on line 34 Fatal error: Uncaught TypeError: pg_fetch_assoc(): Argument #1 ($result) must be of type resource, null given in /home/nikic/php/php-src/t036.php:34 Stack trace: #0 /home/nikic/php/php-src/t036.php(34): pg_fetch_assoc(NULL) #1 {main} thrown in /home/nikic/php/php-src/t036.php on line 34 Exactly as expected and explained before. If you do not see the error message, you need to look at your error handlers and your error related ini settings (do you have error_reporting=E_ALL? Do you have at least one of display_errors=1 or enabled logging? If you are logging, did you check your log?) In any case, this is not a bug in PHP.