|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 20:00:02 2025 UTC |
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.