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

[BUG]: Loader should not load already loaded files #15489

Closed
michalzielanski opened this issue May 13, 2021 · 4 comments · Fixed by #15698
Closed

[BUG]: Loader should not load already loaded files #15489

michalzielanski opened this issue May 13, 2021 · 4 comments · Fixed by #15698
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report external dependency This issue depends on external issue to be resolved. status: low Low

Comments

@michalzielanski
Copy link

I use Phalcon\Loader as the main autoloader, but some libraries (for example laminas/laminas-zendframework-bridge) register their autoloaders to load files before I can do so with $loader->loadFiles(), resulting in a "Cannot redeclare XYZ" error is raised.
Phalcon\Loader should use require_once instead of require so that the error does not appear.

require filePath;

require filePath;

require filePath;

require filePath;

To Reproduce

// file_to_load.php
<?php
function onlyTest()
{
}

// script.php
<?php
$loader = new \Phalcon\Loader();
$loader->register();

$file = __DIR__ . DIRECTORY_SEPARATOR . 'file_to_load.php';
// Simulation of loading by another autoloader.
require $file;

$loader->registerFiles([$file]);
$loader->loadFiles();
@michalzielanski michalzielanski added bug A bug report status: unverified Unverified labels May 13, 2021
@Izopi4a
Copy link
Member

Izopi4a commented May 13, 2021

if you change

require $file;

to

require_once $file;

i think it will be fine. Also i don't think you should be manually including files

@michalzielanski
Copy link
Author

michalzielanski commented May 14, 2021

@Izopi4a, this is just a very simple example showing the bug. In fact, the code that registers the additional autoloader is in the composer package (laminas/laminas-zendframework-bridge required by laminas/laminas-escaper) which in turn is depending on the package I need (phpoffice/phpword:0.18.1).

Besides, you are wrong to replace require $file; with require_once $file; will not change anything, since require_once must be in Phalcon\Loader.

@niden niden added 5.0 The issues we want to solve in the 5.0 release status: low Low and removed status: unverified Unverified labels May 18, 2021
@niden niden added this to Working on it in Phalcon Roadmap May 18, 2021
@niden niden mentioned this issue Jul 8, 2021
5 tasks
@Jeckerson Jeckerson added the external dependency This issue depends on external issue to be resolved. label Aug 15, 2021
@Jeckerson
Copy link
Member

Will be possible to implement since Zephir 0.14.0 stable.

@niden niden mentioned this issue Sep 30, 2021
5 tasks
@niden niden linked a pull request Sep 30, 2021 that will close this issue
5 tasks
@niden
Copy link
Sponsor Member

niden commented Oct 1, 2021

Resolved in #15698

@niden niden closed this as completed Oct 1, 2021
Phalcon Roadmap automation moved this from Working on it to Implemented Oct 1, 2021
@niden niden moved this from Implemented to Released in Phalcon Roadmap Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report external dependency This issue depends on external issue to be resolved. status: low Low
Projects
Archived in project
Phalcon Roadmap
  
Released
Development

Successfully merging a pull request may close this issue.

4 participants