PHP core files

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

PHP core files

Post by Oren »

Does anybody know where I can view the core code of a specific PHP function?

The PHP manual on is_file() says: "is_file — Tells whether the filename is a regular file". What do they mean by "regular file"?
I would like to see the implementation of the is_file() function (it is written in C if memory serves...).
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

The PHP download page: http://www.php.net/downloads.php

Under "Complete Source Code".
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Regular file probably means that it it's not a directory or symbolic link.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Thanks guys, I'll take a look and tell you if I find anything that is worth to mention.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Ok, I downloaded it... Any ideas where I can find the is_file() function?
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Oren wrote:Thanks guys, I'll take a look and tell you if I find anything that is worth to mention.
I think it uses fstat(), there's a do_fstat() in php-5.2.1>ext>main>streams>plain_wrapper.c
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Oh ... There's reference to is_file() in php-5.2.1 > ext > standard > filestat.c

Looks like it uses the streams statbuf though ... which is how I wound up in plain_wrapper.c
User avatar
dreamscape
Forum Commoner
Posts: 87
Joined: Wed Jun 08, 2005 10:06 am
Contact:

Post by dreamscape »

I believe all they mean by "regular file" is that it is in fact a file and not a directory. I will also return true if the file is a symbolic link that points to a file.

I think they say "regular file" because the file_exists() function works on both files and directories.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

They used the words regular to thwart the question of "what kind of file?" Think of it as "Regular, every day, generic file."
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I wonder why it resolves symlinks. A symbolic link is not a file.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Yes, it is a file. It's data contains the path to that of the linked file - the OS recognises this and thus it appears as a shortcut. Much like the Windows ".lnk" files appear as shortcuts, this is what a symbolic link is.

a Hard linked file is what does not appear as it's own file, as that is actually a shared inode, not a 'redirect' as symlinks are.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Thanks Buddha443556, dreamscape, Jenk and astions, thanks guys.

I did not find it, but I don't think I need it anymore, your help was enough so I don't need to see the core code.
With that said, if someone has already found it, I won't mind see the code.

Thanks again guys :wink:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Oren wrote: With that said, if someone has already found it, I won't mind see the code.
It's in ext/standard/filestat.c file, is_file is expanded using FileFunction macro which calls the php_stat function which deep inside of it calls the php_stream_stat_path_ex and then uses the following macro to check if the file is regular:

Code: Select all

#ifndef S_ISREG
#define S_ISREG(mode)   (((mode)&S_IFMT) == S_IFREG)
#endif
where mode is ssb.sb.st_mode obtained from php_stream_stat_path_ex

P.S.: dig deeper if you want :D
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Oh thanks Weirdan.

I know some C, but very basic. Can you explain in words/pseudo code what these lines mean?

Code: Select all

#ifndef S_ISREG
#define S_ISREG(mode)   (((mode)&S_IFMT) == S_IFREG)
#endif 
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's called a macro. What the macro does is perform a bitwise comparison of mode and the constant S_IFMT then compares that result with S_IFREG.
Post Reply