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

[Autoloader] include_once is not needed on Autoloader::loadClass() with no namespace #4756

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented May 31, 2021

include_once is not needed on get class with no namespace for Autoloader::loadClass() call as it try to get app\Config that autoloaded.

Checklist:

  • Securely signed commits

@samsonasik samsonasik changed the title [Autoloader] include_once is not needed on config() with no namespace [Autoloader] include_once is not needed on Autoloader::loadClass() with no namespace May 31, 2021
@samsonasik samsonasik force-pushed the include_once_not_needed_on_config_no_namespace branch from 1ef1f78 to a9d0ad8 Compare May 31, 2021 03:39
@samsonasik
Copy link
Member Author

samsonasik commented May 31, 2021

The test for it is already in :

public function testloadClassConfigFound()
{
$this->loader->addNamespace('Config', APPPATH . 'Config');
$this->assertSame(
APPPATH . 'Config' . DIRECTORY_SEPARATOR . 'Modules.php',
$this->loader->loadClass('Modules')
);
}
public function testloadClassConfigNotFound()
{
$this->loader->addNamespace('Config', APPPATH . 'Config');
$this->assertFalse($this->loader->loadClass('NotFound'));
}

also proven in other tests like config('App') in other tests.

Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm missing something. If a non-namespaced file is found, this will now just return the file path without include_once it. So where will this get loaded? Will this be delegated in the next autoload function registered?

@samsonasik
Copy link
Member Author

Actually, it should just return false as it somehow handled by Fabricator, iirc, it previously was needed as cause class redeclare, @paulbalandan what do you think of non - namespace return false?

@samsonasik
Copy link
Member Author

@paulbalandan looking at the previous change on this, this was introduced for faster load due to loadLegacy() at #3413 .

As the loadLegacy() no longer exists, it is safe to just return false early. On looking on Config class, eg: 'Modules' config, there is config('Modules') usage for that.

I updated at 81c5454

@samsonasik samsonasik merged commit 638a5d7 into codeigniter4:develop Jun 1, 2021
@samsonasik samsonasik deleted the include_once_not_needed_on_config_no_namespace branch June 1, 2021 04:46
@samsonasik
Copy link
Member Author

@MGatner @paulbalandan thank you for the review.

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

Successfully merging this pull request may close these issues.

None yet

3 participants