'ClassNotFoundException: Attempted to load class "TwigExtension" from the global namespace

I'm trying to create a Twig Extension using the service container, but i'm getting a "ClassNotFoundException".

Here the exception:

ClassNotFoundException: Attempted to load class "TwigExtension" from the global namespace in \path\to\symfony-simple-blog\src\YagoQuinoy\SimpleBlogBundle\Twig\BlogExtension.php line 11. Did you forget a use statement for this class? Perhaps you need to add a use statement for one of the following: Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension

Here the code:

Twig extension:

namespace YagoQuinoy\SimpleBlogBundle\Twig;

/**
 * Description of BlogExtension
 *
 * @author [email protected]
 */
class BlogExtension extends \TwigExtension
{

    public function getFilters() {
        return array(new \Twig_SimpleFilter('timeAgo', array($this, 'timeAgoFilter')));
    }

    public function timeAgoFilter() {

        return 'yolo!';
    }

    public function getName() {
        return 'blog_extension';
    }
}

service.yml

services:
    yago_quinoy_simple_blog.twig.blog_extension:
        class: YagoQuinoy\SimpleBlogBundle\Twig\BlogExtension
        tags:
            - { name: twig.extension }

Edit: Solved.

smarber Twig_Extension not TwigExtension, symfony.com/doc/current/cookbook/templating/twig_extension.html



Solution 1:[1]

You can still update to Symfony 4.4 by fixing your twig version in your composer.json by running

composer require twig/twig ~2.0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Meriem Bader