php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79811 Script stops and delivers incomplete web page
Submitted: 2020-07-08 16:23 UTC Modified: 2020-07-09 13:47 UTC
From: buschmann at nidsa dot net Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 8.0.0alpha2 OS: Windows Server 2019 64bit
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: buschmann at nidsa dot net
New email:
PHP Version: OS:

 

 [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






Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-08 16:27 UTC] nikic@php.net
The call is probably throwing a TypeError, but something in your error/exception handling setting eats it.
 [2020-07-08 16:46 UTC] cmb@php.net
> The call is probably throwing a TypeError, but something in your
> error/exception handling setting eats it.

That's quite likely.  However, to exclude any potential OPcache
issues, please run the script with OPcache disabled.
 [2020-07-08 17:30 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2020-07-09 07:09 UTC] buschmann at nidsa dot net
-Status: Feedback +Status: Open
 [2020-07-09 07:09 UTC] buschmann at nidsa dot net
I have tried it with opcache disabled, same error:

The Zend OPcache extension is installed but not active

The code comes from the php 4 era and has no explicit exception handling.

The variable $rSOrder is only declared inside of this function as global and not set before.

It should be easyly reproducable by declaring the function, calling the loop with dummy echos and some dummy echos after the loop.


The core problem is that the script stops processing (different from 7.x.y).
 [2020-07-09 08:24 UTC] cmb@php.net
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.
 [2020-07-09 08:27 UTC] nikic@php.net
-Package: opcache +Package: PostgreSQL related
 [2020-07-09 13:24 UTC] buschmann at nidsa dot net
-PHP Version: 8.0.0alpha1 +PHP Version: 8.0.0alpha2
 [2020-07-09 13:24 UTC] buschmann at nidsa dot net
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>
 [2020-07-09 13:28 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2020-07-09 13:28 UTC] nikic@php.net
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.
 [2020-07-09 13:47 UTC] buschmann at nidsa dot net
In my case this does not throw a fatal error.

Have you tested my script under Windows?

I have error_log enabled, E_ALL.

In the error log I only get 1 line per call as:

[09-Jul-2020 15:35:53 Europe/Berlin] PHP Warning:  Undefined variable $rSOrder in N:\cpsdev\cps\cps_pg\hbtest.php on line 34
and then nothing more.

I have tried it on the same machine with php 7.4.8 and get multiple lines of

[09-Jul-2020 15:28:58 Europe/Berlin] PHP Notice:  Undefined variable: rSOrder in N:\cpsdev\cps\cps_pg\hbtest.php on line 34
[09-Jul-2020 15:28:58 Europe/Berlin] PHP Warning:  pg_fetch_assoc() expects parameter 1 to be resource, null given in N:\cpsdev\cps\cps_pg\hbtest.php on line 34
...

but the script terminates and shows all content in browser (view source).

I have switched back to the php8 delivered pqlib.dll but same error.

Here are my current error settings from phpinfo:

PHP Version 	8.0.0alpha2
Directive	Local Value	Master Value
allow_url_fopen	On	On
allow_url_include	Off	Off
arg_separator.input	&	&
arg_separator.output	&	&
auto_append_file	no value	no value
auto_globals_jit	On	On
auto_prepend_file	no value	no value
browscap	no value	no value
default_charset	UTF-8	UTF-8
default_mimetype	text/html	text/html
disable_classes	no value	no value
disable_functions	no value	no value
display_errors	Off	Off
display_startup_errors	On	On
doc_root	no value	no value
docref_ext	no value	no value
docref_root	no value	no value
enable_dl	Off	Off
enable_post_data_reading	On	On
error_append_string	no value	no value
error_log	L:/ZZ_log/php_log_prod/php_err.log	L:/ZZ_log/php_log_prod/php_err.log
error_prepend_string	no value	no value
error_reporting	32767	32767
expose_php	On	On
extension_dir	N:\Apache\php8\ext	N:\Apache\php8\ext
file_uploads	On	On
hard_timeout	2	2
highlight.comment	#FF8000	#FF8000
highlight.default	#0000BB	#0000BB
highlight.html	#000000	#000000
highlight.keyword	#007700	#007700
highlight.string	#DD0000	#DD0000
html_errors	On	On
ignore_repeated_errors	On	On
ignore_repeated_source	Off	Off
ignore_user_abort	Off	Off
implicit_flush	Off	Off
include_path	.;C:\php\pear	.;C:\php\pear
input_encoding	no value	no value
internal_encoding	no value	no value
log_errors	On	On
log_errors_max_len	4096	4096
mail.add_x_header	On	On
mail.force_extra_parameters	no value	no value
mail.log	no value	no value
max_execution_time	600	600
max_file_uploads	20	20
max_input_nesting_level	64	64
max_input_time	60	60
max_input_vars	20000	20000
memory_limit	512M	512M
open_basedir	no value	no value
output_buffering	4096	4096
output_encoding	no value	no value
output_handler	no value	no value
post_max_size	8M	8M
precision	14	14
realpath_cache_size	4096K	4096K
realpath_cache_ttl	120	120
register_argc_argv	Off	Off
report_memleaks	On	On
report_zend_debug	On	On
request_order	GP	GP
sendmail_from	no value	no value
sendmail_path	no value	no value
serialize_precision	17	17
short_open_tag	Off	Off
SMTP	localhost	localhost
smtp_port	25	25
sys_temp_dir	no value	no value
syslog.facility	LOG_USER	LOG_USER
syslog.filter	no-ctrl	no-ctrl
syslog.ident	php	php
unserialize_callback_func	no value	no value
upload_max_filesize	2M	2M
upload_tmp_dir	O:/cpsprod/tmp_upload	O:/cpsprod/tmp_upload
user_dir	no value	no value
user_ini.cache_ttl	300	300
user_ini.filename	.user.ini	.user.ini
variables_order	GPCS	GPCS
windows.show_crt_warning	Off	Off
xmlrpc_error_number	0	0
xmlrpc_errors	Off	Off
zend.assertions	1	1
zend.detect_unicode	On	On
zend.enable_gc	On	On
zend.exception_ignore_args	Off	Off
zend.multibyte	Off	Off
zend.script_encoding	no value	no value
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 00:01:30 2024 UTC