Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

dynamic class loading - Attempted to load class _CLASS_ from namespace _NAMESPACE_

$
0
0

So i try to load a class inside a service in Symfony4.It doesn't matter if i load it as classname or as App\to\class\name\classname.
It generates the same error.

Other posts said you need to add the whole fully qualified classname..
This doesn't work. Am I missing something?Code below:

<?php// src/Service/AdwordsService.phpnamespace App\Service;use App\Service\AdTypes\ExpendedTextAdTypes as ExpendedTextAdTypes;class AdwordsService{     ...    public function getAdsModel($ad) //<-- for example "EXPANDED_TEXT_AD"    {        $type = explode('_',strtolower($ad->getType()));        $modelName = array_map('ucfirst', $type);        $modelName = implode('',$modelName).'Types';        // will load ExpandedTextAdTypes        return new $modelName($ad);    }    ...}

Class that it tries to load:

<?php// src/Service/AdTypes/ExpendedTextAdTypes.phpnamespace App\Service\AdTypes;class ExpendedTextAdTypes{    private $adData;    public function __construct($ad)    {        $this->adData = $ad;    }}

Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>