Page 1 of 1

Wrong parameter count for fwrite()

Posted: Tue Mar 03, 2009 5:14 pm
by becky-atlanta
Here is my test codes:

Code: Select all

<?php
$test_file = "test".date("mdy").".htm";
$fh = fopen($test_file, 'w') or die("can't open file");
 
function echoWrite($mystring) {
    echo $mystring;
    fwrite($fh = $mystring . "\n");
}  
echoWrite("Let me see if this works.");
echoWrite("Wow, amazing!");
echoWrite("This is so exciting.");
fclose($fh);
?>
Here is the output?

Let me see if this works.
Warning: Wrong parameter count for fwrite() in ... on line 7
Wow, amazing!
Warning: Wrong parameter count for fwrite() in ... on line 7
This is so exciting.
Warning: Wrong parameter count for fwrite() in ...p on line 7

What did I do wrong?

Re: Wrong parameter count for fwrite()

Posted: Tue Mar 03, 2009 5:35 pm
by requinix
Have you considered looking at the code to see if it's correct? If maybe you made a typo?

Re: Wrong parameter count for fwrite()

Posted: Tue Mar 03, 2009 6:00 pm
by becky-atlanta
I have looked at it over and over and over again.

I just changed

Code: Select all

fwrite($fh = $mystring . "\n");
to

Code: Select all

fwrite($fh, $mystring);
I am getting a different error:

Warning: fwrite(): supplied argument is not a valid stream resource...

Re: Wrong parameter count for fwrite()

Posted: Tue Mar 03, 2009 6:15 pm
by requinix

Code: Select all

function echoWrite($mystring) {
    echo $mystring;
    fwrite($fh, $mystring);
}
How does the function know what $fh is? It wouldn't know about $mystring if you hadn't told it...