tibberous Posted March 3, 2010 Share Posted March 3, 2010 floatval / intval would ignore $ signs (ie: floatval("$5.25") would be 5.25, instead of 0 ) There would be a shorter version of mysql_real_escape_string, or even better, a shorter version of mysql_real_escape_string(trim()) Using [] on a non-array would initialize it as an array Quote Link to comment https://forums.phpfreaks.com/topic/193969-little-things-youd-change-with-php/ Share on other sites More sharing options...
Daniel0 Posted March 3, 2010 Share Posted March 3, 2010 floatval / intval would ignore $ signs (ie: floatval("$5.25") would be 5.25, instead of 0 ) That's ridiculous. Why would it do that? What about "£5.52" or "DKK 5.52" or millions of other things that could be regarded as numbers? floatval / intval would ignore $ signs (ie: floatval("$5.25") would be 5.25, instead of 0 ) There would be a shorter version of mysql_real_escape_string, or even better, a shorter version of mysql_real_escape_string(trim()) Here you go: function my_mysql_escape($string, $link = null) { return mysql_real_escape_string(trim($string), $link); } It's not PHP's job making endless of aliases for you. Using [] on a non-array would initialize it as an array Just cast to array. daniel@daniel-laptop:~$ php -r "var_dump((array) 'foo');" array(1) { [0]=> string(3) "foo" } Quote Link to comment https://forums.phpfreaks.com/topic/193969-little-things-youd-change-with-php/#findComment-1020800 Share on other sites More sharing options...
Dennis1986 Posted March 3, 2010 Share Posted March 3, 2010 I was just about to post, but then Daniel0 did and I was going to write something similar, so I'm just going with "what he said". Quote Link to comment https://forums.phpfreaks.com/topic/193969-little-things-youd-change-with-php/#findComment-1020801 Share on other sites More sharing options...
roopurt18 Posted March 3, 2010 Share Posted March 3, 2010 There would be a shorter version of mysql_real_escape_string, or even better, a shorter version of mysql_real_escape_string(trim()) Use PDO. It's better anyways. Or just wrap it in your own alias as daniel suggested. No reason you can't name it mres or sql_escape or z if you want to be lazy and non-descriptive. Quote Link to comment https://forums.phpfreaks.com/topic/193969-little-things-youd-change-with-php/#findComment-1021061 Share on other sites More sharing options...
tibberous Posted March 3, 2010 Author Share Posted March 3, 2010 Didn't say there were critical, just that they would make the language better. If floatval stripped everything to the first number, I'd be happy -- returning 0 when there are digits in the string really doesn't make sense. If the people who made PHP weren't worried about convenience when they wrote the language, we wouldn't have anything near what we have now. The ? operator, the foreach loop, $arr[] = $x, the for loop, ect. are all just shortcuts for things that could be done with only slightly more code. Quote Link to comment https://forums.phpfreaks.com/topic/193969-little-things-youd-change-with-php/#findComment-1021090 Share on other sites More sharing options...
waynew Posted March 3, 2010 Share Posted March 3, 2010 floatval / intval would ignore $ signs (ie: floatval("$5.25") would be 5.25, instead of 0 ) That's ridiculous. Why would it do that? What about "£5.52" or "DKK 5.52" or millions of other things that could be regarded as numbers? floatval / intval would ignore $ signs (ie: floatval("$5.25") would be 5.25, instead of 0 ) There would be a shorter version of mysql_real_escape_string, or even better, a shorter version of mysql_real_escape_string(trim()) Here you go: function my_mysql_escape($string, $link = null) { return mysql_real_escape_string(trim($string), $link); } It's not PHP's job making endless of aliases for you. Using [] on a non-array would initialize it as an array Just cast to array. daniel@daniel-laptop:~$ php -r "var_dump((array) 'foo');" array(1) { [0]=> string(3) "foo" } function m($string, $link = null) { return mysql_real_escape_string(trim($string), $link); } pwned Quote Link to comment https://forums.phpfreaks.com/topic/193969-little-things-youd-change-with-php/#findComment-1021122 Share on other sites More sharing options...
Daniel0 Posted March 3, 2010 Share Posted March 3, 2010 No. Fail for not being able to quote people properly Quote Link to comment https://forums.phpfreaks.com/topic/193969-little-things-youd-change-with-php/#findComment-1021124 Share on other sites More sharing options...
waynew Posted March 3, 2010 Share Posted March 3, 2010 No. Fail for not being able to quote people properly WUT? Quote Link to comment https://forums.phpfreaks.com/topic/193969-little-things-youd-change-with-php/#findComment-1021131 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.