[TYPO3-core] RFC #15020: Enhancement of t3lib_div::testInt

Michiel Roos [netcreators] michiel at netcreators.com
Wed Jul 7 10:07:38 CEST 2010


On 7/7/10 9:00 AM, Dmitry Dulepov wrote:
> Hi!
> 
> Michiel Roos [netcreators] wrote:
>> Problem:
>> t3lib_div::testInt can be optimized by making use of the PHP version of
>> testInt called: is_int.
> 
> I think there is an issue here. Here is the description of is_int from the
> PHP manual:
> 
> ==============
> Finds whether the type of the given variable is integer.
> Note: To test if a variable is a number or a numeric string (such as form
> input, which is always a string), you must use is_numeric().
> ==============
> 
> I just checked: is_int('5') gives false, while t3lib_div::testInt('5')
> gives true. The idea of the later is to see if the argument can be
> ~interpreted~ as integer while the former checks if it ~is~ integer. The
> difference is important.
> 
> -1 to the patch because it breaks the behavior. Sorry.
> 

Ah, I see. This was not immediately clear to me from the description of
the function. Since the description just says 'Tests if the input is an
integer'. Only the description of the return value hints at special
handling of string cases: 'Returns true if string is an integer'.

I've added a test script that echoes the result too.

I've also added an alternative function to the test:

  return (is_int($var) || !strcmp($var, intval($var)));

but alas, it performs worse on 'int disguised as string' than the original.

So, unless we have any other suggestions, please close the bug report.

-- 
Met vriendelijke groet / Warm regards,

Michiel Roos
Chief Technical Officer
Netcreators: Open Source, Open Minds, Open People
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 15020_testInt_test_v2.php
Type: text/php
Size: 2188 bytes
Desc: not available
URL: <http://lists.typo3.org/pipermail/typo3-team-core/attachments/20100707/bf581174/attachment.bin>


More information about the TYPO3-team-core mailing list