php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46998 include inside include generates junk output
Submitted: 2009-01-03 23:43 UTC Modified: 2009-01-04 12:03 UTC
From: ian at ianhobson dot co dot uk Assigned:
Status: Closed Package: *General Issues
PHP Version: 5.2.8 OS: windows 2000
Private report: No CVE-ID: None
 [2009-01-03 23:43 UTC] ian at ianhobson dot co dot uk
Description:
------------
include-ing a file that includes another file before producing any output, results in a few invalid characters being emitted before the <DOCTYPE> line



Reproduce code:
---------------
Create a file with any trivial content. 

Include, require or require_once it from a second file. This second file needs the php tags and the include line only. 

Include this second file in a page like this (which is valid). 
 
<?php // test0.php
require_once "test1.php";
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>Test Demo Page</title>
</head><body>
<p>This page has junk before the doctype</p>
</body></html>

Expected result:
----------------
The source should start with the "<" of the doctype line as its first character. 

Actual result:
--------------
In iIE source, you will see 6 squares before the <!DOC...

In Firefox validator it will complain about invalid characters in the prolog. 

If you move the content of the inner file up a level, all works correctly. 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-03 23:44 UTC] ian at ianhobson dot co dot uk
My server is set up to use utf8. I did not notice this problem when using Latin1.
 [2009-01-04 02:42 UTC] jani@php.net
BOM?
 [2009-01-04 12:03 UTC] ian at ianhobson dot co dot uk
indeed yes - thanks. 

I re-coded all my source files in utf-8 without BOM and everything started to work as expected. 

This report is bogus - but contains information that may be useful to others. Perhaps something for the manual?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC