Doctrine 1
  1. Doctrine 1
  2. DC-629

Doctrine Integer Validator should use intval() rather than round(floatval())

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.0-ALPHA1, 1.2.0-ALPHA2, 1.2.0-ALPHA3, 1.2.0-BETA1, 1.2.0-BETA2, 1.2.0-BETA3, 1.2.0-RC1, 1.2.0, 1.2.1, 1.2.2, 1.2.3
    • Fix Version/s: None
    • Component/s: Validators
    • Labels:
      None
    • Environment:
      Ubuntu 9.10 x64, php 5.2.10

      Description

      echo PHP_INT_MAX;
      echo "\n";
      echo strval(round(floatval(PHP_INT_MAX)));
      

      on 64 bit machine, default php install, you get:

      9223372036854775807
      9.22337203685E+18

      float precision is set to 12 by default. setting it higher offers no benefit, with it set to 20+, it still doesn't match up (and is actually not reliably past a certain length, i'd have to dig again to find a reference though), but as you can see, no go:

      9223372036854775807
      9223372036854775808

      as a result, very large #'s do NOT validate as doctrine integers, even though they are.

      fix, use intval() instead. as far as I can tell, and as far as our 400+ unit tests in our application show, PHP_INT_MAX is fully supported everywhere else except for in Validator.php@170:

      170c170
      <                  return (string) $var == strval(round(floatval($var)));
      ---
      >                  return (string) $var == strval(intval($var));
      

        Activity

        Hide
        Jonathan H. Wage added a comment -

        This breaks a test:

        
        Doctrine_Ticket_1783_TestCase...................................................failed
        
        
        Doctrine_Ticket_1783_TestCase : method testValidateLargeIntegers failed on line 17 
        
        Show
        Jonathan H. Wage added a comment - This breaks a test: Doctrine_Ticket_1783_TestCase...................................................failed Doctrine_Ticket_1783_TestCase : method testValidateLargeIntegers failed on line 17

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Stephen Ostrow
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: