php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29279 echo "0"; terminates output
Submitted: 2004-07-20 13:47 UTC Modified: 2009-08-06 04:22 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: milky at users dot sf dot net Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.0.0 OS: Linux, glibc2.3
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: milky at users dot sf dot net
New email:
PHP Version: OS:

 

 [2004-07-20 13:47 UTC] milky at users dot sf dot net
Description:
------------
(Hard to reproduce.)

In one of my scripts any variant of outputting a variable set to (string) "0" ended the output. Appearantly happened for var_dump(), print_r(), echo() and print().

Initially it appeared to be a pcre problem:
$_SERVER["QUERY_STRING"] = "q=example&s=0&s=1&s=7";
preg_match_all('/&s=(\d+)/', $_SERVER["QUERY_STRING"], $uu);
echo implode(" ", $uu[1]);

But it probably isn't. Appears that earlier parts of any of the other included scripts changed interpreter behaviour and lead to the strange effect. It seems not configuration-related or to be a general bug, as the same <?php echo "0";' ?> gives no problem in short scripts.

Only fails in CGI environment, doesn't happen on cmdline.

same effect:
- echo "0";
- echo '0';

OTH this doesn't output anything strange (binary):
- echo "1";

Not sure, if this is a bug at all. The "0" breaks also with 5rc2, 4.3.x and down to 4.1.2 (all in -cgi/fcgi incarnation)

But btw:
  echo "\000"; echo "+++";
  echo "0"; echo "...";
will correctly return the ^@+++ but nothing after that.

related to #16388 ?


Reproduce code:
---------------
<?php
//...
#...
#
include("htm/head");   # contains no php code
echo "0";              # ends output

// more code follows
#... (all other code and include()s being commented out to reproduce)
?>



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-28 12:21 UTC] tony2001@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.


Any log entries? Any reproduce script?
 [2004-08-05 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-08-06 03:52 UTC] ccheeboon at yahoo dot com
to reproduce:
File: open_target.php, contain only below code:
<?php 
echo "1";
?>

File: test.php, contain the following code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

	if( isset($_POST['remove_subscriber_form']) )
	{//if form submitted
		$u_phone =rawurlencode ( $_POST['phone'] );
		$u_shortcode = rawurlencode( $_POST['shortcode'] );
		$u_keyword = rawurlencode( $_POST['keyword'] );
		$u_timestamp = rawurlencode( $_POST['timestamp'] );		
		
		$loadurl = "http://www.mysite/";
		
		$a = fopen($loadurl."open_target.php?phone=$u_phone&shortcode=$u_shortcode&keyword=$u_keyword&timestamp=$u_timestamp","r");
		
		$tmp = "";		
		
		while( $b=fread($a,100) )
		{
			$tmp .= $b;
		}
		
		echo "affected subscriber=(".$tmp.")<br />";
			
		fclose($a);
		flush;
	
	}

?>
</body>
</html>

/////////////
upload both file to ur server.
NOTE: you have to change $loadurl to according to ur server. 
RUNNING test.php when open_target.php [echo "0";],the zero do not appear. However if target.php [echo "-1";] or other, the echo content appear.
 [2009-08-06 04:09 UTC] ccheeboon at yahoo dot com
CORRECTION:
File: test.php, contain the following code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

	
		$u_phone =rawurlencode ( $_POST['phone'] );
		$u_shortcode = rawurlencode( $_POST['shortcode'] );
		$u_keyword = rawurlencode( $_POST['keyword'] );
		$u_timestamp = rawurlencode( $_POST['timestamp'] );		
		
		$loadurl = "http://www.mysite/";
		
		$a =
fopen($loadurl."open_target.php?phone=$u_phone&shortcode=$u_shortcode&ke
yword=$u_keyword&timestamp=$u_timestamp","r");
		
		$tmp = "";		
		
		while( $b=fread($a,100) )
		{
			$tmp .= $b;
		}
		
		echo "affected subscriber=(".$tmp.")<br />";
			
		fclose($a);
		flush;
	
	

?>
</body>
</html>
 [2009-08-06 04:22 UTC] rasmus@php.net
Isn't this just because you are doing:

  while($b=fread())

if fread() returns 0 that becomes while(0)

I think you mean:

  while(strlen($b=fread($a,100)))

or, the more traditional:

  while(!feof($a)) $tmp .= fread($a,100);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC