-
☆ A M B ☆
- 24,524 Posts
I'm trying to create a custom output modifier to automatically convert incoming GET values to int. I had presumed it would be quite simple:
<?php
return intval($input);
However, this (and other variations on the theme) doesn't appear to have any impact whatsoever on the output, which in the case of a string like pagetitle should be returning 0.
discuss.answer
seems you will need to return a string since 2.3
return (string) intval($input);
-
☆ A M B ☆
- 24,524 Posts
Interesting. Is this documented anywhere officially?
-
☆ A M B ☆
- 24,524 Posts
Yes, since you are appending a string to the value PHP will automatically convert it to a string. Likewise something like '42' + 0 will automatically convert the string 42 to an integer so the addition operation can be performed.
However, in your example the space at the beginning of the numeric string may or may not be acceptable to the function using the resulting string. Better to specifically cast it to a string.
FYI, this would be faster (if it works -- not sure if two casts in a row will work). IIRC, casts are about twice as fast as a conversion function.
return (string) (int) $input;