php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24967 fopen when placed within a function causes function to return
Submitted: 2003-08-06 16:13 UTC Modified: 2003-08-07 07:12 UTC
From: laurie at oneuponedown dot co dot uk Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 4.3.2 OS: Linux
Private report: No CVE-ID: None
 [2003-08-06 16:13 UTC] laurie at oneuponedown dot co dot uk
Description:
------------
When using fopen inside a function to open a file for 
reading - irrerspective of weather fopen successfully opens 
the file, the use of fopen causes the function to return.




Reproduce code:
---------------
<html>
<head>
<title>TEST</title>
</head>
<body>
<?
function test () {
// OPEN FILE FOR READING
if ($ID = @fopen("/tmp/213.212.78.27.1060201522.txtfgbxdf","wb")) {

// NOTHING FROM HERE DOWNWARDS IS EXCUTED

// PRINT FIRST LINE OF FILE
print(fgets($ID));
} else {
// PRINT ERROR
print("FOPEN FAILED");
}
}
?>
</body>
</html>


Expected result:
----------------
First line of file if success, "FOPEN FAILED" if fail.

Actual result:
--------------
Nothing

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-06 16:33 UTC] wez@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

Remove the @ from the fopen() call, and then go read the manual.
 [2003-08-07 05:14 UTC] laurie at oneuponedown dot co dot uk
The prior example does not imply a bug I agree, incorrect 
example SORRY half asleep.

The following example recreates the problem experienced. 
Whilst the following arrangement may appear redundant this 
is obviously a reduced version of the actual code.

<?
class test {
var $ID;
var $OUTPUT;

function test() {
return $this->test2();
}

function test2() {
// OPEN OUTPUT_FILE FOR READING
$this->ID = 
@fopen("/tmp/213.212.78.27.1060201522.txt","rb");

if ($this->ID) {
$OUTPUT = fgets($this->ID);
return TRUE;
} else {
$OUTPUT = "ERROR";
return FALSE;
}
}
}

$TEST = new test();

print_r($TEST);
?>

Expected Output:
test Object
(
    [ID] => Resource id
    [OUTPUT] => (FIRST LINE OF FILE OR ERROR)
)

Actual Output:
test Object
(
    [ID] => Resource id
    [OUTPUT] => 
)

Fopen opens resource but then causes function to return 
with none of the code following it within the test2 
function being executed. Removing fopen results in all of 
the test2 function code being executed. Popen also causes 
the same issue.
 [2003-08-07 07:12 UTC] laurie at oneuponedown dot co dot uk
New example also incorrect - $OUTPUT not class defined 
$this->OUTPUT, once this is corrected this example does not 
exhibit the bug. I will update once I have an example.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC