views:

104

answers:

1

When I moved my sites to a dedicated server from HostGator, several things were broken and all are broken involving type coercion. If $_POST['var'] is 0, it is not considered to be an integer and fails a comparison with another integer.

I went through and forced int types on all of those broken places on the site I found, but I'm sure there are more I didn't find. I'm not crazy familiar with PHP.ini configuration, but perhaps you are and can tell me how I can fix this?

Thanks

+5  A: 

No - you can't change PHPs type conversion functionality, but you can write your code to better deal with PHP's dynamic type conversion.

All request vars are automatically treated as strings. Without seeing your code it's rather hard to establish what your criteria for "fails a comparison" are.

If I run:

print var_export((0=="0"), true) . "\n";
print var_export(("0"==0), true) . "\n";
print var_export((0==(integer)"0"), true) . "\n";
print var_export((0==="0"), true) . "\n";

Then I get

true
true
true
false

i.e. the only time the integer comparison fails is when I ask for a match on type as well as value.

symcbean
So you're saying the issue is probably more so involved with a possible PHP version change?
Webnet
I'm saying that I can't conceive why your code is failing if it is written correctly - and I doubt its got much to do with PHP versions.
symcbean