Jump to content

Recommended Posts

Hi,

 

I have started using php a few days ago. I like what I've seen so far, but I have a question about inconsistent function name patterns.

 

Consider fopen/fclose and opendir/closedir. Why not openfile/closefile, or dopen/dclose? I know that naming conventions evolve over time, and I would understand the difference if these functions came from different releases - but they both deal with elementary file system access, so I assume they were introduced in the same release?

 

Not a complaint, I'm honestly just curious...

Link to comment
https://forums.phpfreaks.com/topic/283195-inconsistent-function-name-patterns/
Share on other sites

Those four names are inherited from C/C++ and general Linux programming.

 

[edit] If you're going to have a hard time with things like differing function names then consider learning a different language.

Edited by requinix

A lot of PHP's early/basic functions use the same name and parameter lists as their C equivalents. They are like simple wrappers around the C functions to allow them to be used from within PHP. This makes it so someone with knowledge of C can easily jump into PHP, but conversely it results in odd conventions like this. As the language was being built in the early days there was less standardization/planning as well so whoever would add a particular extension/function would often just use whatever their personal style was when deciding the name/parameters of the functions. As a result, you end up with a bunch of mixed styles such as runonsfornames, or using_underscores_for_separators or ($needle,$haystack) rather than ($haystack,$needle) etc.

 

While it'd be nice if all this got re-done to follow a more consistent standard, such a job is not really practical due to backwards compatibility concerns. As such you just need to either remember all the tiny variations or just keep the manual at your fingertips so you can look up the functions when you can't remember.

Haha, yes, wait till you use strip_tags() and stripslashes(), but wait, there's more....  how about some functions take ($needle, $haystack) and some take ($haystack, $needle)?  That would be just plain crazy.

 

EDIT: Seconds late

Edited by AbraCadaver

As such you just need to either remember all the tiny variations or just keep the manual at your fingertips so you can look up the functions when you can't remember.

Euhm.. no. I remember shit, I got an IDE that does the remembering for me :) PHP, Perl, Python, VB.NET, Java, C, C++, Assembler, .. right.. try to remember that!

Edited by ignace

As a result, you end up with a bunch of mixed styles such as runonsfornames, or using_underscores_for_separators or ($needle,$haystack) rather than ($haystack,$needle) etc.

 

Arrays are needle, haystack... string functions are haystack, needle. Easy to remember! Although I'd love for it all to be the same :(

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.