Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 4 comments

2 participants

@doctrinebot

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

@doctrinebot

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

Issue was closed with resolution "Invalid"

@doctrinebot

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

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.

@Ocramius Ocramius was assigned by doctrinebot
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.