Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generation of autoloader incorrect #1710

Closed
rejinka opened this issue Mar 19, 2013 · 23 comments
Closed

Generation of autoloader incorrect #1710

rejinka opened this issue Mar 19, 2013 · 23 comments

Comments

@rejinka
Copy link

rejinka commented Mar 19, 2013

I get really strange "class not found"-fatal-errors with composer since my last composer::selfupdate. Standard classes of symfony/symfony like the ParameterBag or Request could not be found.

Yesterday i had a small chat with apanek in the composer channel in freenode. He told me to give you everything in the following gist with hope someone can "shed some light on that": https://gist.github.com/rejinka/5186727

Right now with my autoload-files "Assetic\Extension\Twig\AsseticExtension" can not be found.

P.S.: Composer version d929a08

@Seldaek
Copy link
Member

Seldaek commented Mar 19, 2013

Did you check that the vendors installed properly? In some rare cases it happens that something gets broken I think, and you might not have a complete assetic or something. rm -rf vendor/kriswallsmith/assetic && composer install should make sure assetic is properly installed.

@rejinka
Copy link
Author

rejinka commented Mar 19, 2013

Yes, i did. I multiple tried to remove the complete vendor directory and install it with composer again.

@rejinka rejinka closed this as completed Mar 19, 2013
@rejinka
Copy link
Author

rejinka commented Mar 21, 2013

sorry, clicked the wrong button...

@rejinka rejinka reopened this Mar 21, 2013
@Seldaek
Copy link
Member

Seldaek commented Mar 21, 2013

Well I'm unfortunately not sure what to tell you here. Which php version & OS are you running?

@rejinka
Copy link
Author

rejinka commented Mar 21, 2013

Fedora 17 with php 5.4.9 and in my virtual machine Debian 6.0.7 with php 5.4.12

@Seldaek
Copy link
Member

Seldaek commented Mar 22, 2013

OK, not even old PHP.. I tried with your composer.json and I can load that assetic class just fine.

@donaldducky
Copy link

I've come across the same issue with version 57c3403 of composer.

Project structure
Directory structure is kind of awkward but looks like this:

root/
  project/
    composer.json
  common/
    src/
      MyNamespace/
        MyClass.php

Composer file
composer.json file:

{
    "autoload": {
        "psr-0": {
            "MyNamespace": "../common/src"
        }
    }
}

Composer command
The command I used (in the root directory) was:

composer install --working-dir project

Actual result
The project/vendor/composer/autoload_namespaces.php file shows:

<?php

// autoload_namespaces.php generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'MyNamespace' => $baseDir . '/common/src',
);

Expected result
But the previous version of composer that I used (842155d) showed the path to be the correct one:

<?php

// autoload_namespaces.php generated by Composer

$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);

return array(
    'MyNamespace' => $baseDir . '/../common/src',
);

@Seldaek
Copy link
Member

Seldaek commented Apr 3, 2013

@donaldducky I pushed a fix for your issue (which is unrelated to the original problem of this ticket).

@rejinka any luck getting things to work?

@donaldducky
Copy link

@Seldaek Thanks for the fix! Do you have the version that fixes this? (ie. can I self-update?)

I didn't create a new issue because this one sounded similar.

@Seldaek
Copy link
Member

Seldaek commented Apr 3, 2013

Yup you can run self-update, it should fix it.

@TiGR
Copy link

TiGR commented Apr 10, 2013

Since this is open, I'll post here. I get similar "Class not found" errors on server (not on local machine). Composer is of the same version on both machines - 894f530. PHP version differs. Everything is okay on PHP 5.4.6 and the error triggers at PHP 5.3.13.

composer.json (minified to only bogus library):

{
    "require": {
        "nusphere/nusoap": "0.9.5"
    },
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "nusphere/nusoap",
                "version": "0.9.5",
                "dist": {
                    "url": "http://downloads.sourceforge.net/project/nusoap/nusoap/0.9.5/nusoap-0.9.5.zip",
                    "type": "zip"
                },
                "autoload": {
                    "classmap": ["lib/"]
                }
            }
        }
    ]
}

Files autoload_classmap.php are different. Here is the difference:

-     'nusoap_base' => $vendorDir . '/nusphere/nusoap/lib/class.nusoap_base.php',
-     'nusoap_client' => $vendorDir . '/nusphere/nusoap/lib/class.soapclient.php',
+     'nusoap_base' => $vendorDir . '/nusphere/nusoap/lib/nusoap.php',
+     'nusoap_client' => $vendorDir . '/nusphere/nusoap/lib/nusoap.php',
...
-     'soapclient' => $vendorDir . '/nusphere/nusoap/lib/class.soapclient.php',
+     'soapclient' => $vendorDir . '/nusphere/nusoap/lib/nusoap.php',

nusoap.php file is compilation of all classes in that directory. I understand that this kind of files do not look really well, but different behavior on different machines is alarming and should not happen.

@Seldaek
Copy link
Member

Seldaek commented Apr 11, 2013

@TiGR this looks like a filesystem sorting issue which makes it scan one dir before the other depending on the machine. Not really alarming. Anyway if nusoap.php is a compilation of everything, it should find the classes. I don't see why you would get class not found errors?

@TiGR
Copy link

TiGR commented Apr 11, 2013

@Seldaek First it loads some class from separate file. Next, it loads nusoap.php, where already loaded class is also present. As php meets already defined class it throws fatal error.

Well, actually my error is not "Class not found", but "Cannot redeclare defined class".

Huh, I suppose this should be a separate issue.

@Seldaek
Copy link
Member

Seldaek commented Apr 11, 2013

Yes indeed reporting a new issue would be best.

@TiGR
Copy link

TiGR commented Apr 11, 2013

@Seldaek is it possible to split it or should I repost?

@Seldaek
Copy link
Member

Seldaek commented Apr 11, 2013

You can copy your comment in a new issue, github doesn't allow splitting.

@TiGR
Copy link

TiGR commented Apr 11, 2013

Done, thanks. issue #1790

@toopay
Copy link

toopay commented Dec 31, 2013

I randomly encounter same issue. Restarting web-server seems resolve that. It complains some classes were not exists.

Weird.

@Seldaek
Copy link
Member

Seldaek commented Jan 2, 2014

@toopay my guess is that's an APC cache issue, but I may be wrong.

@Seldaek Seldaek closed this as completed Jan 2, 2014
@darektw
Copy link

darektw commented Dec 3, 2014

@toopay any luck getting things to work?
I need to reset my php service each time I want develop other symfony project.
For example I have 2 projects with different bundles and virtualhosts for them.
Lets call them 'ck' and 'z'.

If I first enter ck.lo in my web browser -> ck.lo works, but z.lo not, and after restart php if I first enter z.lo in webbr. z.lo works but ck.lo not.

If project 'z' doesnt work it shows error like thisone

ClassNotFoundException: Attempted to load class "ComurImageBundle" from namespace "Comur\ImageBundle" in /home/darek/public_html/z/app/AppKernel.php line 30. Do you need to "use" it from another namespace?

After digging I noticed that file app/cache/dev/classes.php.meta has wrong paths for classes

darek@darek:~/public_html/z > grep -r "cklocal" .
./app/cache/dev/classes.php.meta:a:2:{i:0;a:128:{i:0;s:121:"/home/darek/public_html/cklocal/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php";i:1;s:121:"/home/darek/public_html/cklocal/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/SessionListener.php";i:2;s:123:"/home/darek/public_html/cklocal/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php";

my phpinfo http://pastebin.com/6FSPwrNt

@toopay
Copy link

toopay commented Dec 3, 2014

@darektw I'm not remember when this issue were resolved in my end, but yeah i never encounter similar issue. I would assume there is something wrong with your cache, @Seldaek should be able to explain better on that.

I do still have interminent memory issue (i guess similar to #1898) and were using HHVM to run the composer and alleviate the issue.

@rejinka
Copy link
Author

rejinka commented Dec 3, 2014

@Seldaek sorry, i forgot this issue. Yes, i got things running and yes, your guess was correct, the problem was not related to composer, but to some php caching.

So... For me, resolved.

@mclemme
Copy link

mclemme commented Jan 20, 2015

Ran into the exact same issue, Ubuntu 12.04 LTS (server) w/ PHP 5.4.36 and APC enabled. Disabling APC makes the problem go away.

But disabling APC was not an option, so running sudo service php5-fpm restart after running composer install and stuff works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@Seldaek @donaldducky @TiGR @toopay @mclemme @rejinka @darektw and others