Gaurav Pandey
Gaurav Pandey

Reputation: 2796

fwrite not working

Is there a way to know why fwrite is not working? I mean as in .net (I am a .net guy) the method just throws the exception which can be caught and the exception message and stack trace message tells all the story why the .net method didn't work. Is there any way I can know why my fwrite is not working as I think my code is stable because it's working fine on one machine but not on the other. Please help. Thanks in advance.

Edit: It's just returning false leading me nowhere. :(

Upvotes: 3

Views: 1516

Answers (2)

Gaurav Pandey
Gaurav Pandey

Reputation: 2796

fwrite is like int fwrite ( resource $handle , string $string [, int $length ] )

In my case, it was the $length of the file in fwrite was not being passed correctly, that's why it was not working.

Upvotes: 0

mario
mario

Reputation: 145472

Also: If you rather want to have exceptions instead of error messages/warnings, then don't use the basic file system functions. Open your file like this:

$f = new SplFileObject("output", "w");
$f->fwrite("error");

That's maybe closer to what .NET has. (In practice this just leads to the same warning messages, so go for error_reporting(E_ALL); fist.)

Upvotes: 3

Related Questions