Jump to content

Why is this?


Garethp

Recommended Posts

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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

:facepalm:

Link to comment
Share on other sites

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.  :P

Link to comment
Share on other sites

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.  :P

 

Hmm... remind me to make use of the  :sarcastic:  smiley next time. And you're right, I don't have connections with anyone important. I'm merely a low class{} PHP peasant / grunt  :geek: , so no offense taken.

Link to comment
Share on other sites

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.