[TYPO3-dev] behaviour of t3lib_div::testInt has been changed

Helmut Hummel helmut at typo3.org
Fri Sep 10 00:16:33 CEST 2010


On 09.09.10 19:52, Steffen Kamper wrote:
> Hi,
> 
> this shows that the modification breaks other code. I wonder why this is 
> not obvious in the unit tests.

Well that's because the unittests do not cover these cases:

'10.' == '10' evaluates to TRUE in PHP
'10.00' == '10' evaluates to TRUE in PHP

Even the case Dmitry braught up in the long thread about improving this
function is not covered by the tests:

!strcmp(' 5',intval(' 5'))
	false

(intval(' 5') == ' 5')
	true

This is still the case for the committed version:

((string)intval(' 5') == ' 5')
	true

wondering why this is false:

((string)intval('5 ') == '5 ')
	false

I would not expect this to be different to the above example.

And there are other cases where the behaviour changed:
With '+1234', '01234' and '-01234'
current function also returns true, whereas the old returned false.


To keep the behaviour like before, I do not see a better solution than
reverting the change (and enhancing the unit tests to cover the cases
mentioned).


OK, while playing around a bit, I found this one working:

return (string)intval($var) === (string)$var;

I did not check the performance though.

And it should be checked if returning false for '+1234', '01234' and
'-01234' is the intended behaviour of the function.


Attached the changed unittests I used.

Regards Helmut


More information about the TYPO3-dev mailing list