Wrong parameter count for fwrite()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
becky-atlanta
Forum Commoner
Posts: 74
Joined: Thu Feb 26, 2009 6:26 pm
Location: Atlanta, GA

Wrong parameter count for fwrite()

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Wrong parameter count for fwrite()

Post by requinix »

Have you considered looking at the code to see if it's correct? If maybe you made a typo?
User avatar
becky-atlanta
Forum Commoner
Posts: 74
Joined: Thu Feb 26, 2009 6:26 pm
Location: Atlanta, GA

Re: Wrong parameter count for fwrite()

Post 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...
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Wrong parameter count for fwrite()

Post 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...
Post Reply