Jump to content

Little things you'd change with PHP


tibberous

Recommended Posts

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

 

 

Link to comment
Share on other sites

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"
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

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.