tags:

views:

207

answers:

7

There are a number of functions that have bugs / weird interfaces / security issues etc. which do you think is worst?

+1  A: 

Personally, a function that should -logically1- return a useful value, variable (etc) but instead returns a boolean (to indicate success or failure) is amongst the most annoying functions. My own example of this is:

$array = array("apples","oranges","bananas","plums");

$shuffled_array = shuffle($array);

echo "$shuffled_array"; // echoes the value "1"

I don't know about other people but, for me (and this is perhaps a fault with my own understanding of the underlying science, philosophy...whatever), this should return a shuffle()-ed array.


1: Obviously for a very subjective value of 'logically.'

David Thomas
Did you try this instead?echo $shuffled_array;
Chris Ballance
Not until you suggested it just now, but it does exactly the same (thankfully...I thought I must've been blatantly dumb for a second there). =)
David Thomas
@Chris, vars in double quotes are evaled in PHP. Per php.net/shuffle, it returns a bool value so this example, and your comment would both print the same thing
Mike B
I just tried passing an empty array and an array of all the same values to shuffle(). It still returns true. If you don't give it a reference you get a fatal. So, what actually constitutes a "failure" to this function? Does it ever return false?
Ollie Saunders
It generates a warning if you try to pass it something that's *not* an array `$not_array = "apples"; shuffle($not_array);` but *false*? I honestly don't know. One of the many reasons this particular function annoys me... =/
David Thomas
shuffle() returns false if it fumbles and drops the cards on the table. It happens more often if you get it drunk first.
Frank Farmer
+4  A: 

All of the array functions that can't seem to get the needle/haystack order implemented similarly.

All of the string functions that can't decide whether to use an underscore between words or not. strip_tags() and stripslashes()

Mike B
+4  A: 

Personally, I hate the fact that some functions do not have the same parameters order... For example:

http://us2.php.net/manual/en/function.in-array.php

AND

http://us3.php.net/manual/en/function.stristr.php

In both you specify $haystack and $needle, but in different orders. I hate when those are swapped from function to function.

Seb
+5  A: 

I hate min and max. I can never remember what they do. Min and max what?! Why not use some kind of useful name, like smallest_value_in_the_following_list() and biggest_element_in_this_array_or_set_of_parameters(). Stupid PHP.

Oh and don't even get me started on rand(). Nearly everytime I call it I get a different answer.

Kip
+1 for humour... I get different results every time I call rand() too ;-)
scunliffe
A: 

get_magic_quotes_gpc() ... PHP should have never used magic quotes.

fuentesjr
A: 

I don't like strpos.

"Find position of first occurrence of a string"... "Returns the position as an integer."

e.g. if the first character, returns 0, second, returns 1, etc.

however unlike Java, Javascript or many other languages... if it isn't found, it doesn't return an integer e.g. -1, it returns a boolean FALSE instead.

scunliffe
for the downvoter(s), care to comment?
scunliffe
A: 

Wow, no-one has mentioned eval() ... ?

Noon Silk