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

Composer replaces class names in plugins with _composer_tmp0 #5237

Closed
Ocramius opened this issue Apr 23, 2016 · 3 comments
Closed

Composer replaces class names in plugins with _composer_tmp0 #5237

Ocramius opened this issue Apr 23, 2016 · 3 comments

Comments

@Ocramius
Copy link
Contributor

Ocramius commented Apr 23, 2016

First, note that this happens sporadically, and I didn't yet identify which state transition causes the composer PluginManager to do that.

Specifically, my plugin looks like following:

class MyPlugin
{
    const SOMETEMPLATE = <<<'PHP'
final class GeneratedThing
{
}
PHP;

    // ...
}

Composer seems to generate a temporary class to be passed to eval() in some conditions.
I cannot reproduce the bug yet, but it seems seems related to optimized classmaps.
The replacement of the class names is done via a regular expression.
The regular expression doesn't recognize the difference between class MyPlugin (class definition) and final class GeneratedThing (within a string), and replaces both instances with respectively MyPlugin_composer_tmp0 and final class GeneratedThing_composer_tmp0.

The offending regex should probably be replaced with AST-aware code.

@Ocramius Ocramius changed the title Composer sometimes replaces class names in templates with _composer_tmp0 Composer replaces class names in plugins with _composer_tmp0 Apr 23, 2016
Ocramius added a commit to Ocramius/PackageVersions that referenced this issue Apr 23, 2016
Ocramius added a commit to Ocramius/PackageVersions that referenced this issue Apr 23, 2016
@Ocramius
Copy link
Contributor Author

Meanwhile, worked around this bug via Ocramius/PackageVersions#16

@Ocramius
Copy link
Contributor Author

Ocramius commented Apr 23, 2016

I managed to reproduce this bug thanks to @BarthyB:

Given following composer.json:

{
    "require": {
        "vich/uploader-bundle": "1.0.1",
        "ocramius/package-versions": "1.0.3"
    }
}

Run a composer install (output not relevant).

Then check vendor/ocramius/package-versions/src/PackageVersions/Versions.php. File should start with something like following:

<?php

namespace PackageVersions;

/**
 * ...
 */
final class Versions
{

Run composer require oneup/uploader-bundle (output not relevant).

Check the vendor/ocramius/package-versions/src/PackageVersions/Versions.php file again:

<?php

namespace PackageVersions;

/**
 * ...
 */
final class Versions_composer_tmp0
{

Ocramius added a commit to Ocramius/PackageVersions that referenced this issue Apr 23, 2016
@sbuzonas
Copy link
Contributor

Effort to leverage the internal tokenizer can be reused in #5239

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

2 participants