Bug #52984 [Com]: PHP executing text from .php file opened with fopen().

From: Date: Mon, 04 Oct 2010 11:25:32 +0000
Subject: Bug #52984 [Com]: PHP executing text from .php file opened with fopen().
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-154890@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52984&edit=1 ID: 52984 Comment by: craig at logicshock dot co dot uk Reported by: craig at logicshock dot co dot uk Summary: PHP executing text from .php file opened with fopen(). Status: Bogus Type: Bug Package: *Directory/Filesystem functions Operating System: Ubuntu 8.10/9.04, Windows 7 x86 PHP Version: Irrelevant Block user comment: N New Comment: As an update, I altered the code.php file to see if the contents made a difference. The changed file is: // This is a test comment, doesnt matter that it is not in the php tags because this // file SHOULD NEVER BE EXECUTED! <?php echo " This is a test<?php ?>"; ?> Now, the resulting output should be that exact text as the reading script is only reading the text, not executing it. However the result is instead: // This is a test comment, doesnt matter that it is not in the php tags because this // file SHOULD NEVER BE EXECUTED! "; ?> There is something wrong here, because it is reading parts and not others.... To be sure I tried it on my Windows machine (PHP 5.3.1) , and again on two of my Linux servers (PHP 5.2.6 & 5.3.3), the result is the same on all three. I still cannot see any coding error. Surely this is a bug? Previous Comments: ------------------------------------------------------------------------ [2010-10-04 12:53:20] craig at logicshock dot co dot uk The actual code is shown here, am I missing a mistake here then? The original code was a lot bigger but I broke it down to the code shown below to help isolate the problem. I had a colleague look too, he also couldn't see anything wrong, still I will check the code again just in case my last 12 months of forced ASP.net has made me overlook something. There was an echo added, I forgot to show that in the first post here, so added it as an edit, shown below. ------------------------------------------------------------------------ [2010-10-04 12:45:16] pajoye@php.net Works just fine here, 5.2/5.3, obviously. Also adding an echo should help to output the data. Double check your actual code, there is certainly an error in it. ------------------------------------------------------------------------ [2010-10-04 12:40:39] craig at logicshock dot co dot uk The text: Calling script (index.php): ls_execute(); Should read: Calling script (index.php): echo ls_execute(); ------------------------------------------------------------------------ [2010-10-04 12:39:22] craig at logicshock dot co dot uk Description: ------------ While trying to use a PHP script to read the contents of another .php file using fopen(), it appears that PHP might be executing/skipping/altering the text as PHP code instead of treating it as plain text. The result is nothing like as would be expected as shown below, the result is missing lots of text. 2 versions of PHP have been tried 5.3.1 and 5.3.3 on Windows Vista and 7 both x86 and on two versions of Ubuntu server 8.10 & 9.04, the result is the same across all testbeds. Tried using fgets, fread and file_get_contents, all display the same result. This error was reproduced and verified by a colleague. Test script: --------------- Calling script (index.php): ls_execute(); function ls_execute() { $fp = fopen('code.php', 'r') or die('Cannot open that source resource'); while(!feof($fp)) $data .= fread($fp,128); fclose($fp); return $data; } The file to be read (code.php): <?php echo " This is a test!"; ?> Expected result: ---------------- <?php echo " This is a test!"; ?> Actual result: -------------- "; ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52984&edit=1

« previous php.bugs (#154890) next »