tags:

views:

48

answers:

2

On the php manual we can read:

fwrite() returns the number of bytes written

Ok... but what kind of thing is "number of bytes written"?

Binary string? Binary number? Stream? Int?

I'm a little bit lost here.

Regards

+8  A: 

From the manual:

Description

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

It returns an int on success, as indicated by the type name just before the function name. It returns FALSE on error:

fwrite() returns the number of bytes written, or FALSE on error.

Andy E
I didn't notice the type before the function. :( Ok. Let's forget this question ever existed. I've learn today that, I can see the return type on the PHP manual. :D~
MEM
But it should have been `mixed` since it can return `FALSE` too; `0 !== false`.
jensgram
@jensgram maybe the types written on php manual presuppose the type on success only? Perhaps? I'm guessing...
MEM
@MEM Could be. I don't know, either :-S
jensgram
@jensgram Almost all functions return FALSE when they fail and return NULL when wrong arguments are given. The return value type is documented for success, otherwise everything would be mixed.
Artefacto
@Artefacto Sounds reasonable :)
jensgram
+1  A: 

An integer, or boolean false on failure.

$fh = fopen('/tmp/bar', 'w');
$bytes = fwrite($fh, 'Hello, world.');

var_dump($bytes); // output: int(13)
Adam Backstrom