Thread: Type casting
View Single Post
Old 05-25-2008, 04:00 PM   #6 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
Type casting is not made so you can 'transform' strings into integers, arrays, objects, and so on. It's made so you can ENFORCE a certain data type. Its only use is that you can make sure you're getting a certain data type, so you can perform a certain operation. See the example:

PHP Code:
function sum_ints($a$b)
{
    
$a = (int) $a;
    
$b = (int) $b;

    return 
$a+$b;

It's obvious that the sum function can't be used on strings, so that's why we use type casting, so we can enforce the parameters to be integers. If non-integer values are passed in, the function will simply return 0 instead of crashing if you pass in objects as parameters, therefore not breaking application flow. Operator overloading would come useful in here, but that's another problem.
Thanks, also Village_Idiot, my main priority in making dynamic SQL Applications, is security, then features, and I like to encrypt the strings that go into the table, and the such and such, like always, you can give me tips on MySQL, though I've learned pretty much all of it, EXCEPT all the of proper security really, besides using comments and quotes to block certain things out so someone could do an sql injection.

I'm usually the paranoid type, when it comes to working on security, I'm always scared that someone would destroy my application, :( that is why I backup logs every time there are new active queries. I am going to extreme measures to make my own language or add a new extension in php, using C/C++.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote