Avoid object to throw incorrect exception for integerish

Fixed a problem where intval is used for an object and this may lead to a exception from the object or a notice. According to the php manual `intval() should not be used on objects`.