Garethp Posted October 8, 2009 Share Posted October 8, 2009 Why does the array_pop() function only return the last item in the array? When I worked with python for the day that I worked, there was a array.pop(index) function that would let you choose which index you popped, and it was an optional paramater too. Why isn't PHP like that? I mean, it's not exactly a hard thing to do. I built my own function within five minutes to do it. I know that I can just use mine, I'm just wondering why they didn't do it from the start... Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/ Share on other sites More sharing options...
Daniel0 Posted October 8, 2009 Share Posted October 8, 2009 Because pop and push operates on a stack, i.e. in a LIFO like manner. The function you're looking for is called array_splice. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-932853 Share on other sites More sharing options...
Mark Baker Posted October 8, 2009 Share Posted October 8, 2009 Why does the array_pop() function only return the last item in the array? because that's what "pop" means in computer jargon. I mean, it's not exactly a hard thing to do. I built my own function within five minutes to do it. I know that I can just use mine, I'm just wondering why they didn't do it from the start...Probably because it's so easy for you to do yourself... two lines of code is all you need. Why should the PHP core developers provide you with a dedicated function to do what can be done with just two function calls anyway? PHP's biggest problem is the sheer number of functions that most people aren't even aware exist... they don't need more functions, they need to streamline those they already have, and get rid of a lot of the duplicates, but then people complain about them being deprecated Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-932854 Share on other sites More sharing options...
Daniel0 Posted October 8, 2009 Share Posted October 8, 2009 Personally, I wouldn't mind if PHP 6 broke backwards compatibility and got properly reorganized in a logical manner. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-932859 Share on other sites More sharing options...
trq Posted October 8, 2009 Share Posted October 8, 2009 Personally, I wouldn't mind if PHP 6 broke backwards compatibility and got properly reorganized in a logical manner. Â Me either. It really does need a good clean-up. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-932862 Share on other sites More sharing options...
Garethp Posted October 8, 2009 Author Share Posted October 8, 2009 Why does the array_pop() function only return the last item in the array? because that's what "pop" means in computer jargon. I mean, it's not exactly a hard thing to do. I built my own function within five minutes to do it. I know that I can just use mine, I'm just wondering why they didn't do it from the start...Probably because it's so easy for you to do yourself... two lines of code is all you need. Why should the PHP core developers provide you with a dedicated function to do what can be done with just two function calls anyway? PHP's biggest problem is the sheer number of functions that most people aren't even aware exist... they don't need more functions, they need to streamline those they already have, and get rid of a lot of the duplicates, but then people complain about them being deprecated  Which is my point precicely. Why should you have both pop and splice if you can make pop do both? That's having two functions do one functions work Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-932867 Share on other sites More sharing options...
trq Posted October 8, 2009 Share Posted October 8, 2009 Which is my point precicely. Why should you have both pop and splice if you can make pop do both? That's having two functions do one functions work  I'm not sure that's what Daniel and myself were alluding to (pardon me if I am wrong but...). PHP has allot of inconsistencies when it comes to the way built in's receive arguments. It would also be nice (seeing as php6 has namepspaces) to move certain functionality out of the global namespace and into more organised modules.  Functions still should serve a single particular purpose IMO. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-932943 Share on other sites More sharing options...
KevinM1 Posted October 8, 2009 Share Posted October 8, 2009 Personally, I wouldn't mind if PHP 6 broke backwards compatibility and got properly reorganized in a logical manner.  I would pay money for this. Seriously. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-932948 Share on other sites More sharing options...
trq Posted October 8, 2009 Share Posted October 8, 2009 Personally, I wouldn't mind if PHP 6 broke backwards compatibility and got properly reorganized in a logical manner.  I would pay money for this. Seriously.  I'm sure that could be organised. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-932950 Share on other sites More sharing options...
Mark Baker Posted October 8, 2009 Share Posted October 8, 2009 Which is my point precicely. Why should you have both pop and splice if you can make pop do both? That's having two functions do one functions work  I'm not sure that's what Daniel and myself were alluding to (pardon me if I am wrong but...). PHP has allot of inconsistencies when it comes to the way built in's receive arguments. One prime example is the order in which arguments are passed to built in functions that perform similar functions strpos ($haystack, $needle); array_search ($needle , $haystack);  Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-932967 Share on other sites More sharing options...
salathe Posted October 8, 2009 Share Posted October 8, 2009 One prime example is the order in which arguments are passed to built in functions that perform similar functions strpos ($haystack, $needle); array_search ($needle , $haystack); I won't deny that things are far from consistent across the language, but things should generally be fairly consistent within different libraries/extensions. In the FAQ, a recent entry (not yet propagated across all mirrors) briefly mentions this problem. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-932981 Share on other sites More sharing options...
xylex Posted October 8, 2009 Share Posted October 8, 2009 Personally, I wouldn't mind if PHP 6 broke backwards compatibility and got properly reorganized in a logical manner.  This one actually came up when Rasmus Lerdorf was at our meetup. He pointed out that PHP 4 is still being used fairly widespread because of backwards compatibility issues with PHP 5, and the only way there would be a faster conversion to PHP 6 is if there were little to no backwards compatibility issues.  And honestly, if you really want to be working with a language that's clean and organized but hardly any existing software/scripts can run on it, why don't you just use Python? Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933000 Share on other sites More sharing options...
Daniel0 Posted October 8, 2009 Share Posted October 8, 2009 I am using other languages as well, but it would be nice if PHP was also well organized. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933020 Share on other sites More sharing options...
KevinM1 Posted October 8, 2009 Share Posted October 8, 2009 What I'd really like to see would be consistency between function names. A quick look at the function reference shows that a lot are multiple words jammed together without any separator, and all in lower case. Examples:  datetime() htmlentities() htmlspecialchars() isset() phpinfo() A whole bunch of string manipulation functions...  The majority, however, use an underscore to separate words:  array_diff() in_array() is_int() mysql_real_escape_string()  Trivial? Probably, but it's frustrating having to keep track of little language idiosyncrasies like this. A consistent naming scheme - which must be enforced by libraries/plugins/modules/whatever - is all I'm asking for. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933025 Share on other sites More sharing options...
xylex Posted October 8, 2009 Share Posted October 8, 2009 isset() is intentionally different than is_array(), is_int(), etc because isset() is a language construct and the rest of them are functions. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933071 Share on other sites More sharing options...
trq Posted October 8, 2009 Share Posted October 8, 2009 And honestly, if you really want to be working with a language that's clean and organized but hardly any existing software/scripts can run on it, why don't you just use Python? Â What on earth does that mean? There's allot of great software written in Python. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933356 Share on other sites More sharing options...
xylex Posted October 8, 2009 Share Posted October 8, 2009 And honestly, if you really want to be working with a language that's clean and organized but hardly any existing software/scripts can run on it, why don't you just use Python?  What on earth does that mean? There's allot of great software written in Python.  Not picking up the sarcasm if it's intended. But for example:  http://www.hotscripts.com/  18,201 PHP scripts vs. 141 Python scripts  Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933378 Share on other sites More sharing options...
corbin Posted October 8, 2009 Share Posted October 8, 2009 ASP.NET only has like 2k, but lots of major websites exist in it.... Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933386 Share on other sites More sharing options...
PugJr Posted October 9, 2009 Share Posted October 9, 2009 ASP.NET only has like 2k, but lots of major websites exist in it....  Thats because PHP is probably the easiest programming language to learn. Well, I can't speak for everyone, but thats for me.  echo "pug"; VS Response.Write("pug")   $pug = 1; if ( $pug == 1 ) { echo "$pug = 1"; } VS Dim pug pug = 1 If pug = 1 Then Response.Write("Variable pug = 1") End If   I think most anyone would agree that the PHP version is easier to do and probably the reason PHP has 18k and ASP has 2k.  EDIT: Correct me if I'm wrong about the ASP. I just copy pasted some ASP on how to do "if" and switched a few things around. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933417 Share on other sites More sharing options...
trq Posted October 9, 2009 Share Posted October 9, 2009 And honestly, if you really want to be working with a language that's clean and organized but hardly any existing software/scripts can run on it, why don't you just use Python?  What on earth does that mean? There's allot of great software written in Python.  Not picking up the sarcasm if it's intended. But for example:  http://www.hotscripts.com/  18,201 PHP scripts vs. 141 Python scripts   I wasn't being sarcastic and I doubt some site called hotscripts is any indication. Most Linux distros wouldn't be what they are today without Python. I guess it depends on where your looking but there's allot of software in use today that is written in Python. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933463 Share on other sites More sharing options...
KevinM1 Posted October 9, 2009 Share Posted October 9, 2009 And honestly, if you really want to be working with a language that's clean and organized but hardly any existing software/scripts can run on it, why don't you just use Python?  What on earth does that mean? There's allot of great software written in Python.  Not picking up the sarcasm if it's intended. But for example:  http://www.hotscripts.com/  18,201 PHP scripts vs. 141 Python scripts   Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933499 Share on other sites More sharing options...
nrg_alpha Posted October 9, 2009 Share Posted October 9, 2009 Guys, no worries.. I'll get on the horn with Rasmus Lerdorf first thing tomorrow morning and get all of PHP's issues sorted out. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933509 Share on other sites More sharing options...
PugJr Posted October 9, 2009 Share Posted October 9, 2009 Guys, no worries.. I'll get on the horn with Rasmus Lerdorf first thing tomorrow morning and get all of PHP's issues sorted out.  If Daniel said this, I could believe it. No offense nrg_alpha, but unless you say you have some connections with smiley artists, I'm not gonna believe that you have connections with any important people. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933519 Share on other sites More sharing options...
nrg_alpha Posted October 9, 2009 Share Posted October 9, 2009 Guys, no worries.. I'll get on the horn with Rasmus Lerdorf first thing tomorrow morning and get all of PHP's issues sorted out.  If Daniel said this, I could believe it. No offense nrg_alpha, but unless you say you have some connections with smiley artists, I'm not gonna believe that you have connections with any important people.  Hmm... remind me to make use of the  smiley next time. And you're right, I don't have connections with anyone important. I'm merely a low class{} PHP peasant / grunt , so no offense taken. Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933771 Share on other sites More sharing options...
448191 Posted October 9, 2009 Share Posted October 9, 2009 But of course Daniel has daily contact with Linus, Bill, and Steve.. (too lazy to figure out which smiley to use) Quote Link to comment https://forums.phpfreaks.com/topic/176929-why-is-this/#findComment-933865 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.