Can someone tell me why when I cast a string of say 00332 I only get back 332? It removes the leading zeros and saves the data in the same format.
Thanks
this->_gate = (string) $this->_linkID->QuoteSmart($gate);
Can someone tell me why when I cast a string of say 00332 I only get back 332? It removes the leading zeros and saves the data in the same format.
Thanks
this->_gate = (string) $this->_linkID->QuoteSmart($gate);
What do you cast it to and why? Let's see the code. If you cast to integer, yeah, integers don't have leading zeroes, so they disappear. No surprise.
I'd say because the leading zeros don't have any importance when cast to an integer.
Maybe you should leave it as a string if you need those leading zeroes, and only cast (int)
on any math needed to be performed (though you could just use the string too, PHP will figure it out)
edit
After seeing the example, I'd want to echo the value before you cast to string (so I can confirm something fishy isn't going on with you QuoteSmart method (or the value your sending as a param, $gate)
Don't cast strings to strings, or any type to the same type for that matter. Typecasting is for changing something from one type to another.
$ php -r 'var_dump((string)"00123");'
string(5) "00123"
Looks like the cast isn't your problem.
OK, here is why it was dropping the leading zeros. It was NOT casting nor addslashes. What I did was to quote the variable (which quotesmart should be doing anyhow but didn't for some reason) Once I quoted the variable, I got the value saved correctly. If Im not mistaken, quotesmart will only work on strings and not ints.