DDC-2739: DBAL/Types/DateType bad argument checking #3428

Closed
opened 2026-01-22 14:19:45 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 13, 2013).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user zephir:

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

Originally created by @doctrinebot on GitHub (Oct 13, 2013). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user zephir: 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
admin added the Bug label 2026-01-22 14:19:45 +01:00
admin closed this issue 2026-01-22 14:19:46 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 16, 2013):

Comment created by @ocramius:

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.

@doctrinebot commented on GitHub (Oct 16, 2013): Comment created by @ocramius: 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.
Author
Owner

@doctrinebot commented on GitHub (Oct 16, 2013):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Oct 16, 2013): Issue was closed with resolution "Invalid"
Author
Owner

@doctrinebot commented on GitHub (Oct 22, 2013):

Comment created by da-eto:

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?

@doctrinebot commented on GitHub (Oct 22, 2013): Comment created by da-eto: 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?
Author
Owner

@doctrinebot commented on GitHub (Oct 22, 2013):

Comment created by @ocramius:

[~da-eto] no, that's really something that is called thousands of times per request. I wouldn't introduce a check there.

@doctrinebot commented on GitHub (Oct 22, 2013): Comment created by @ocramius: [~da-eto] no, that's really something that is called thousands of times per request. I wouldn't introduce a check there.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3428