Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Error: Cannot redeclare class sfyamlinline


Go to End


4 Posts   1656 Views

Avatar
Harley

Community Member, 165 Posts

9 April 2015 at 3:53am

Hi guys,

I've been struggling lately with this on a couple of projects. Basically I've figured out that if I restart Apache then everything is fine once I refresh my page but then every now and again I get the error again usually when creating a new page in the admin:

Fatal error: require_once(): Cannot redeclare class sfyamlinline in /path/to/mysite/framework/thirdparty/zend_translate_railsyaml/library/Translate/Adapter/thirdparty/sfYaml/lib/sfYamlDumper.php on line 11

I'm assuming something somewhere is cached hence it thinks that there is a class which has been duplicated.

Anyone else getting this or does anyone have an idea why it is caused?

Using:

SS 3.1.12
Bitnami MAMP stack 5.4.34-0

Thanks

Avatar
Pyromanik

Community Member, 419 Posts

11 April 2015 at 1:05am

Edited: 11/04/2015 1:06am

I'm not sure about bitnami, but this kind of error usually occurrs when you have a module installed twice (usually by accident), or a 'backup' copy of a class in another (possibly sub)folder.

This seems most odd because it appears to be a core class however. I'm not entirely sure what to do here. But I'd probably still start with the above.

Avatar
Harley

Community Member, 165 Posts

13 April 2015 at 1:58am

Hey Pyromanik, thanks for the response.

Yeah it is unusual, the thing that's really weird is that I've just done the composer installer command to get started and then when I create my modules that's where the trouble begins. As you point out it is core files that seem to be the source of the problem.

I've noticed that any changes to yaml files within _config folders usually kickstart the problem. Once restarting apache the problem goes away. Very odd indeed

Avatar
Pyromanik

Community Member, 419 Posts

13 April 2015 at 10:21pm

After changing yml files you need to perform a flush to get them picked up.
Silverstripe maintains it's own manifest which it uses to define class locations for the autoloader to pick up. After changing yml files (or flushing/building) I can only postulate that as the scan is active it loads classes looking for 'default' configurations (private static $config_things), thus when it runs into a secondary copy of itself, the problem arises.
During normal execution SS relies upon it's own autoloader, so does not seek out classes. This means that although you have two classes of the same name, it doesn't matter.

This is all just best guess though. More investigation should be used to check it out.

So I'd still be looking for accidental double installs. You might have used composer, but you may also have some funny symlink or something that references another install. Or perhaps you have vendor/ in the SS root, but it isn't protected. I'm not entirely sure, but these are all things to check.

Another thing to be wary of is that SS at current is (mostly) not namespaced (in the core classes at least). So you could have some conflict between modules, etc. But again it's a core class (SS uses symfony's yaml reader to parse the configs), so... seems less likely.