Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'Symfony\Component\Yaml\Yaml' not found

I've been struggling for the last day now getting the Symfony Yaml parser working in my application.

My composer.json looks like this;

{
"require": {
    "symfony/class-loader": "2.4.*@dev",
    "symfony/yaml": "2.4.*@dev",
    "facebook/php-sdk": "dev-master"
},
"autoload": {
    "psr-0": {
        "MyApp": "src/"
    }
}

I'm using this in my application:

use Symfony\Component\Yaml\Parser;

$parser = new Parser();
var_dump( $parser->parse( file_get_contents('config.yml') ) );

Then I get this error:

( ! ) Fatal error: Class 'Symfony\Component\Yaml\Yaml' not found in /Projects/my-app/web/index.php on line 16

The UniversalClassLoader (from "symfony/class-loader") works perfectly fine, and when I check what namespaces are loaded, the Symfony\Component\Yaml is the first one in the array.

My IDE (PHPStorm) is giving a squiggly line underneath the classname, "Multiple definitions exist". One is going to the real vendor folder, the other one is referring to a file inside the composer.phar file (read-only).

Does anyone know what I'm doing wrong?

like image 706
Nick Avatar asked Mar 20 '26 19:03

Nick


1 Answers

Show your bootstrap code. Especially where the autoloader is being created.

In general, you should probably use the composer generated autoload file as opposed to the S2 one.

This works:

require_once __DIR__ . '/../vendor/autoload.php';

use Symfony\Component\Yaml\Parser;

$parser = new Parser();

var_dump( $parser->parse( file_get_contents('config.yml') ) );
like image 65
Cerad Avatar answered Mar 24 '26 09:03

Cerad