Author Topic: Type conversion in fuction arg  (Read 375 times)

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Type conversion in fuction arg
« on: April 08, 2010, 08:15:47 AM »
Is there a way to force argument conversion in a function?

Code: [Select]
function aaa((int)$id)
{
        // so I can use:
mysql_query("... WHERE id=$id ");
        // instead of:
mysql_query("... WHERE id='$id' ");
}

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Type conversion in fuction arg
« Reply #1 on: April 08, 2010, 08:21:27 AM »
Nope. However, there is a hackish work-around that can be used to specify integral data types in the function declaration. You have to define your own error handler for this meaning that there's additional overhead for doing it. Check out my framework in the code repository for how this is done. I think it's incredibly useful for catching bugs during development but it should be removed from the code (just like comments and other sub-optimal code) when deploying in production.
Idiocy - Never underestimate the power of stupid people in large groups.


 


SimplePortal 2.3.3 © 2008-2010, SimplePortal