vendor/bin/doctrine won't work, reporting missing 'doctrine.php' #6664

Closed
opened 2026-01-22 15:36:40 +01:00 by admin · 7 comments
Owner

Originally created by @roo7cause on GitHub (Mar 26, 2021).

I was following the doctrine2-ORM Getting Started Guide (just learning about Doctrine) where I encountered a following issue.

ERROR MESSAGE:

PHP Warning:  include(doctrine.php): Failed to open stream: No such file or directory in D:\*mypathtoproject*\DoctrineORM\doctrine2-tutorial\vendor\bin\doctrine(25) : eval()'d code on line 2
PHP Warning:  include(): Failed opening 'doctrine.php' for inclusion (include_path='.;C:\php\pear') in D:\*mypathtoproject*\DoctrineORM\doctrine2-tutorial\vendor\bin\doctrine(25) : eval()'d code on line 2

DOCTRINE CODE:

#!/usr/bin/env php
<?php

/**
 * Proxy PHP file generated by Composer
 *
 * This file includes the referenced bin path (../doctrine/orm/bin/doctrine) using eval to remove the shebang if present
 *
 * @generated
 */

$binPath = realpath(__DIR__ . "/" . '../doctrine/orm/bin/doctrine');
$contents = file_get_contents($binPath);
$contents = preg_replace('{^#!/.+\r?\n<\?(php)?}', '', $contents, 1, $replaced);

if ($replaced) {
    $contents = strtr($contents, array(
        '__FILE__' => var_export($binPath, true),
        '__DIR__' => var_export(dirname($binPath), true),
    ));
    eval($contents);
    exit(0);
}
include $binPath;

This code returns include(doctrine.php), however, this will of course not work, because doctrine.php is NOT present in the current directory where we are executing the vendor/bin/doctrine.

However, when I commented out the if block, the code executed as expected. I assume this works because the $binPath correctly holds the absolute path to where doctrine.php is present.

This raises the question, why do we even do eval() in this script block? including the absolute path to doctrine.php seems to work just nice.

Originally created by @roo7cause on GitHub (Mar 26, 2021). I was following the doctrine2-ORM Getting Started Guide (just learning about Doctrine) where I encountered a following issue. **ERROR MESSAGE:** ``` PHP Warning: include(doctrine.php): Failed to open stream: No such file or directory in D:\*mypathtoproject*\DoctrineORM\doctrine2-tutorial\vendor\bin\doctrine(25) : eval()'d code on line 2 PHP Warning: include(): Failed opening 'doctrine.php' for inclusion (include_path='.;C:\php\pear') in D:\*mypathtoproject*\DoctrineORM\doctrine2-tutorial\vendor\bin\doctrine(25) : eval()'d code on line 2 ``` DOCTRINE CODE: ``` #!/usr/bin/env php <?php /** * Proxy PHP file generated by Composer * * This file includes the referenced bin path (../doctrine/orm/bin/doctrine) using eval to remove the shebang if present * * @generated */ $binPath = realpath(__DIR__ . "/" . '../doctrine/orm/bin/doctrine'); $contents = file_get_contents($binPath); $contents = preg_replace('{^#!/.+\r?\n<\?(php)?}', '', $contents, 1, $replaced); if ($replaced) { $contents = strtr($contents, array( '__FILE__' => var_export($binPath, true), '__DIR__' => var_export(dirname($binPath), true), )); eval($contents); exit(0); } include $binPath; ``` This code returns `include(doctrine.php)`, however, this will of course not work, because `doctrine.php` is NOT present in the current directory where we are executing the `vendor/bin/doctrine`. However, when I commented out the` if block`, the code executed as expected. I assume this works because the `$binPath` correctly holds the absolute path to where `doctrine.php `is present. This raises the question, why do we even do `eval()` in this script block? including the absolute path to `doctrine.php` seems to work just nice.
admin closed this issue 2026-01-22 15:36:40 +01:00
Author
Owner

@greg0ire commented on GitHub (Mar 26, 2021):

Thanks for reporting this, but bear in mind that this script is generated by Composer so even if we (Doctrine) don't need the eval, the fix for that will not happen in doctrine/orm but in composer/composer.

However, when I look at the excerpt of code you are showing, it looks like this could be fixed by using __DIR__. Would you kindly edit vendor/doctrine/orm/doctrine so that it looks like this:

#!/usr/bin/env php
<?php

include(__DIR__ . '/doctrine.php');

And then report back?

@greg0ire commented on GitHub (Mar 26, 2021): Thanks for reporting this, but bear in mind that this script is generated by Composer so even if we (Doctrine) don't need the eval, the fix for that will not happen in `doctrine/orm` but in `composer/composer`. However, when I look at the excerpt of code you are showing, it looks like this could be fixed by using `__DIR__`. Would you kindly edit `vendor/doctrine/orm/doctrine` so that it looks like this: ```shell #!/usr/bin/env php <?php include(__DIR__ . '/doctrine.php'); ``` And then report back?
Author
Owner

@roo7cause commented on GitHub (Mar 26, 2021):

Thanks for reporting this, but bear in mind that this script is generated by Composer so even if we (Doctrine) don't need the eval, the fix for that will not happen in doctrine/orm but in composer/composer.

However, when I look at the excerpt of code you are showing, it looks like this could be fixed by using __DIR__. Would you kindly edit vendor/doctrine/orm/doctrine so that it looks like this:

#!/usr/bin/env php
<?php

include(__DIR__ . '/doctrine.php');

And then report back?

Hey @greg0ire, thanks for comming back to me on this. First, I apologize for opening this issue in Doctrine Project, rather than Composer - thought it was part of the Doctrine.

And yes, if I do the change like you said, it works.

Do you believe this is worth reporting as a some sort of a Bug in Composer ?

@roo7cause commented on GitHub (Mar 26, 2021): > Thanks for reporting this, but bear in mind that this script is generated by Composer so even if we (Doctrine) don't need the eval, the fix for that will not happen in `doctrine/orm` but in `composer/composer`. > > However, when I look at the excerpt of code you are showing, it looks like this could be fixed by using `__DIR__`. Would you kindly edit `vendor/doctrine/orm/doctrine` so that it looks like this: > > ```shell > #!/usr/bin/env php > <?php > > include(__DIR__ . '/doctrine.php'); > ``` > > And then report back? Hey @greg0ire, thanks for comming back to me on this. First, I apologize for opening this issue in Doctrine Project, rather than Composer - thought it was part of the Doctrine. And yes, if I do the change like you said, it works. Do you believe this is worth reporting as a some sort of a Bug in Composer ?
Author
Owner

@greg0ire commented on GitHub (Mar 26, 2021):

Hey @greg0ire, thanks for comming back to me on this. First, I apologize for opening this issue in Doctrine Project, rather than Composer - thought it was part of the Doctrine.

Oh no you're in the right place actually, because as you just proved to yourself it can be fixed here.

And yes, if I do the change like you said, it works.

Then please send a PR

Do you believe this is worth reporting as a some sort of a Bug in Composer?

I'm not sure. When you remove the if block, you said it worked, but doesn't it also print the shebang to the output? #!/usr/bin/env php <-- that's the shebang

@greg0ire commented on GitHub (Mar 26, 2021): > Hey @greg0ire, thanks for comming back to me on this. First, I apologize for opening this issue in Doctrine Project, rather than Composer - thought it was part of the Doctrine. Oh no you're in the right place actually, because as you just proved to yourself it can be fixed here. > And yes, if I do the change like you said, it works. Then please send a PR > Do you believe this is worth reporting as a some sort of a Bug in Composer? I'm not sure. When you remove the if block, you said it worked, but doesn't it also print the shebang to the output? `#!/usr/bin/env php` <-- that's the shebang
Author
Owner

@roo7cause commented on GitHub (Mar 26, 2021):

When I execute this:
$ vendor/bin/doctrine orm:schema-tool:create

with if-block commented out, it outputs:

[OK] No Metadata Classes to process.

This is (at the moment) expected output. I do not see the shebang part though, at least not in my CMD console. Do you expect the shebang output elsewhere?

potential_bug_investigation_doctrine

@roo7cause commented on GitHub (Mar 26, 2021): When I execute this: `$ vendor/bin/doctrine orm:schema-tool:create` with` if-block` commented out, it outputs: ` [OK] No Metadata Classes to process.` This is (at the moment) expected output. I do not see the shebang part though, at least not in my CMD console. Do you expect the shebang output elsewhere? ![potential_bug_investigation_doctrine](https://user-images.githubusercontent.com/10271265/112634406-d653de00-8e3a-11eb-85d9-2dfc8e6cf411.png)
Author
Owner

@roo7cause commented on GitHub (Mar 26, 2021):

@greg0ire I believe that the shebang part is only because of fetching the file contents from the /doctrine/orm/bin/doctrine.

But as for the usage of the script, I am not sure if this is necessary at all. We just need the $binPath to the doctrine.php file., as we want to include it in our project. Maybe this feature is needed for some other OS?

If not, I believe better fix is actually removing all of the REGEX and IF and just send the $binPath to the include statement, which will eventually include the doctrine.php file.

@roo7cause commented on GitHub (Mar 26, 2021): @greg0ire I believe that the shebang part is only because of fetching the file contents from the `/doctrine/orm/bin/doctrine`. But as for the usage of the script, I am not sure if this is necessary at all. We just need the `$binPath` to the `doctrine.php` file., as we want to include it in our project. Maybe this feature is needed for some other OS? If not, I believe better fix is actually removing all of the `REGEX ` and `IF ` and just send the `$binPath` to the `include `statement, which will eventually include the `doctrine.php ` file.
Author
Owner

@greg0ire commented on GitHub (Mar 26, 2021):

I was expecting the shebang to be wrongly output, but it looks like it isn't. So maybe you can try reporting that to Composer.

@greg0ire commented on GitHub (Mar 26, 2021): I was expecting the shebang to be wrongly output, but it looks like it isn't. So maybe you can try reporting that to Composer.
Author
Owner

@roo7cause commented on GitHub (Mar 26, 2021):

Will try reaching out. Thanks.

With this I believe we can close this issue at Doctrine's site. :)

@roo7cause commented on GitHub (Mar 26, 2021): Will try reaching out. Thanks. With this I believe we can close this issue at Doctrine's site. :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6664