5

I was using PHP 7.0.4 and everything was running smoothly and I just upgraded to PHP 7.0.8 and I started getting errors like this one all over the place.

Fatal error: Cannot declare class Plugins\Users\Plugin because the name is already in use in /var/www/html/plugins/Users/Plugin.php on line 8

Does anyone have any idea whats going on, I've been reading through the change logs but that's a patch update it should not break anything?

Additionally, if no solution is found to this problem, how can I downgrade back to 7.0.4? (I'm using ubuntu 16.04 and I just upgraded to the point release)

To sum the comments so far:

  • I have tried disabling opcache this did not solve the problem
  • I am using composer's autoloader - I am not using require or include anywhere
  • This error is happening for a ton of classes, so it is clearly not a code issue (on my part), furthermore the code was working before I upgraded to 7.0.8
php_nub_qq
  • 15,199
  • 21
  • 74
  • 144
  • 1
    Care to share the offending code? – Machavity Jul 28 '16 at 01:10
  • @Machavity It's not a single class, if I remove this class from the code then another class throws this error, it's something in PHP because, as I said, it was all running fine until 30 minutes ago. – php_nub_qq Jul 28 '16 at 01:11
  • error message seems clear –  Jul 28 '16 at 01:12
  • Are you running opcache? There's a longstanding bug that will silently suppress that same fatal. – roippi Jul 28 '16 at 01:14
  • @roippi I was running opcache but I stopped it and the error persists. – php_nub_qq Jul 28 '16 at 01:21
  • how about ... just fixing the error? –  Jul 28 '16 at 01:22
  • @Dagon the error wasn't there before I upgraded to 7.0.8, and I can't find it, if I remove the lines which require the class the error goes away, if I add them even though the class is only used once in the script I get this error - I am using composer's autoloader, that makes me think that it's not an autoloading issue furthermore.. – php_nub_qq Jul 28 '16 at 01:23
  • "if I remove the lines which require the class... I am using composer's autoloader." If you're using composer's autoloader, then you should not have `require`. – bishop Jul 28 '16 at 01:25
  • @bishop I meant the lines that require the usage of the class, not literally `require`, bad selection of words, sorry. – php_nub_qq Jul 28 '16 at 01:26
  • Then the easiest thing to do is, probably, renaming the offending class to something more specific (like `\Plugins\Users\UserPlugin`). – bishop Jul 28 '16 at 01:30
  • @php_nub_qq did you solove this problem.i have the same question. and sometimes some page return out of memory.it seems error in random page. – chatfeed Aug 10 '17 at 10:54
  • @chatfeed yes there is an accepted answer. – php_nub_qq Aug 10 '17 at 11:11

2 Answers2

4

There is not enough data to say definitively, however I suspect opcache. That error, in fact, originates in opcache so I suspect until this point the error had been hidden by one of several opcode bugs, probably #66773.

You legitimately have an autoloading issue that needs to be fixed. Rename the class, check your namespaces, and remove any hard requires.

You might be able to restore the former buggy behavior by disabling/re-enabling opcache or reverting to 7.0.4, but really the bug was only masked by a particular combination of autoloading and opcache. It was, indeed, only by chance that the issue went undetected until now and it'll be only by chance that you can mask it again.

So the best course is to fix the issue.

bishop
  • 37,830
  • 11
  • 104
  • 139
1

Well, apparently I was so blinded by the fact that the error started occurring after the upgrade, that I ignored it even though it was right before my eyes.

These are the first few lines of the class in question (and apparently a bunch of other classes):

<?php

namespace Plugins\Users;

use FW\Utility\Models\Plugins\Plugin;

class Plugin extends Plugin {

As you, and finally I, can clearly see, the class name Plugin is ambiguous, but wasn't in 7.0.4, which is weird and is probably caused by the bug described in bishop's answer

Guess I should have listened to Machavity, huh.

Community
  • 1
  • 1
php_nub_qq
  • 15,199
  • 21
  • 74
  • 144