fox_and_potato Posted October 22, 2013 Share Posted October 22, 2013 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... Quote Link to comment https://forums.phpfreaks.com/topic/283195-inconsistent-function-name-patterns/ Share on other sites More sharing options...
requinix Posted October 22, 2013 Share Posted October 22, 2013 (edited) 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 October 22, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/283195-inconsistent-function-name-patterns/#findComment-1454986 Share on other sites More sharing options...
kicken Posted October 22, 2013 Share Posted October 22, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/283195-inconsistent-function-name-patterns/#findComment-1454990 Share on other sites More sharing options...
AbraCadaver Posted October 22, 2013 Share Posted October 22, 2013 (edited) 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 October 22, 2013 by AbraCadaver Quote Link to comment https://forums.phpfreaks.com/topic/283195-inconsistent-function-name-patterns/#findComment-1454993 Share on other sites More sharing options...
ignace Posted October 22, 2013 Share Posted October 22, 2013 (edited) 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 October 22, 2013 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/283195-inconsistent-function-name-patterns/#findComment-1455000 Share on other sites More sharing options...
Philip Posted October 22, 2013 Share Posted October 22, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/283195-inconsistent-function-name-patterns/#findComment-1455010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.