Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2739

DBAL/Types/DateType bad argument checking

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.3.4
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      class Entity
      {
      /**

      • @ORM\Column(type="date", nullable=true)
        */
        private $date;

      /**

      • @ORM\Column(type="time", nullable=true)
        */
        private $time;

      public function setDate($date)

      { $this->date = $date; }

      public function setTime($time)

      { $this->time = $time; }

      }

      $entity = new Entity();
      $entity->setDate('2013-01-01'); //Fatal error: Call to a member function format() on a non-object in /vendor/doctrine-dbal/lib/Doctrine/DBAL/Types/DateType.php on line 53
      $entity->setTime('00:00'); //Fatal error: Call to a member function format() on a non-object in /vendor/doctrine-dbal/lib/Doctrine/DBAL/Types/TimeType.php on line 53

      EXPECTED any Exception!!!

      https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Types/DateType.php#L50
      https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Types/TimeType.php#L52
      https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Types/DateTimeType.php#L52
      https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Types/DateTimeTzType.php#L70

        Activity

        Hide
        Marco Pivetta added a comment -

        You didn't put a correct type hint on your setters:

        public function setDate(DateTime $dateTime) {...}
        public function setTime(DateTime $time) {...}
        

        That's how you are supposed to use the date types.

        Show
        Marco Pivetta added a comment - You didn't put a correct type hint on your setters: public function setDate(DateTime $dateTime) {...} public function setTime(DateTime $time) {...} That's how you are supposed to use the date types.
        Hide
        Ilya Pleshakov added a comment -

        Hm. Yes, type hint is simple way to achive desired behavior.
        But fatal error from core application component such as Doctrine is very annoying.

        Maybe Doctrine should throw exception on type mismatch rather than fatal error?

        Show
        Ilya Pleshakov added a comment - Hm. Yes, type hint is simple way to achive desired behavior. But fatal error from core application component such as Doctrine is very annoying. Maybe Doctrine should throw exception on type mismatch rather than fatal error?
        Hide
        Marco Pivetta added a comment -

        Ilya Pleshakov no, that's really something that is called thousands of times per request. I wouldn't introduce a check there.

        Show
        Marco Pivetta added a comment - Ilya Pleshakov no, that's really something that is called thousands of times per request. I wouldn't introduce a check there.

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            zephir
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: