file pointer / file handle

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
oboedrew
Forum Commoner
Posts: 78
Joined: Fri Feb 20, 2009 1:17 pm

file pointer / file handle

Post by oboedrew »

I see the terms "file pointer" and "file handle" used a lot in the same context. Are these two terms 100% interchangeable, or is there some subtle difference in meaning?

Thanks,
Drew
rcastera
Forum Newbie
Posts: 4
Joined: Wed Mar 11, 2009 8:07 pm

Re: file pointer / file handle

Post by rcastera »

Hey Drew,

There is a difference between the two. I have tried to explain them both for you below:

File Pointer
This is the position or pointer of where you are currently reading or working in a file.

File Handle
Is a reference to the actual file that you are currently working with.

Hope this helps :wink:
oboedrew
Forum Commoner
Posts: 78
Joined: Fri Feb 20, 2009 1:17 pm

Re: file pointer / file handle

Post by oboedrew »

That distinction makes sense, but is it typically observed? Even in the php manual, it seems file pointer and file handle are used interchangeably in discussing fopen(), fwrite(), fclose(), etc. Is this a distinction that is typically treated carelessly, or am I missing something?

Cheers,
Drew
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: file pointer / file handle

Post by Eran »

Actually in PHP there is no distinction between the two. A file handle is a pointer referencing a file stream (it might not even be a physical file, could be just a memory allocation). It will always point to the current position in the stream, and can be traversed using functions like fseek() and rewind().
Post Reply