Search code examples
phpwindowsformssymfonyintl

Symfony2 date form type: Fatal error: Call to a member function setLenient() on a non-object


thanks to Stof on IRC i know the answer now. I just wanted to share it, in case someone stumbles upon the same problem.

The problem

When you have field type datetime:

/**
 * @ORM\Column(type="datetime", name="released_at")
 */
protected $released_at;

and in form type you use date form type:

$builder
      ->add('released_at', 'date', array(
          'widget' => 'single_text',
          'format' => 'yyyy-MM-dd',
      ));

and you're getting this error:

Fatal error: Call to a member function setLenient() on a non-object in (...)\vendor\symfony\src\Symfony\Component\Form\Extension\Core\Type\DateType.php on line 64


Solution

  • The solution is

    Try this test

    <?php
    
    $formatter = new \IntlDateFormatter();
    
    if($formatter === null)
      echo 'null!';
    else
      echo 'else';
    

    If you get null, it means your php / intl version is buggy and you need to upgrade.

    In my case, I was running @ Windows 7 64bit machine, Wampserver2 with PHP 5.3.8.

    Upgradeing to PHP 5.3.10 or higher did the trick.

    Also if you are getting:

    (..path..)\StubIntlDateFormatter::setLenient() is not implemented. Please install the 'intl' extension for full localization capabilities.

    upgrade to Symfony 2.0.16.

    Cheers and once again, TYVM Stof!