Skip to content

[RFC] Autoload Classmap #6776

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

Closed
wants to merge 6 commits into from

Conversation

markrandall
Copy link

Adds a mechanism to autoload classes based on a static list rather than invoking a userland function.

The classmap is considered authoritative when a key is present. The file must exist, and it must result in the class being loaded.

@michaljusiega
Copy link

There is some performance with this RFC ?

@markrandall
Copy link
Author

There is some performance with this RFC ?

Testing performance in 8.0 is disappointingly minimal, a few percentage points at most vs calling a userland function that checks its own classmap.

@michaljusiega
Copy link

Testing performance in 8.0 is disappointingly minimal, a few percentage points at most vs calling a userland function that checks its own classmap.

Thank you.

@staabm
Copy link
Contributor

staabm commented Mar 16, 2021

There is some performance with this RFC ?

Testing performance in 8.0 is disappointingly minimal, a few percentage points at most vs calling a userland function that checks its own classmap.

Do you expect this could get faster?

If not, what do you think would be the motivation for this change?

@markrandall
Copy link
Author

If not, what do you think would be the motivation for this change?

This is a minor optimization. A few percent on one of the most commonly performed actions completely transparent to the user (subject to uptake by major frameworks such as composer) is still a gain, the change in php-src is minimal.

@gravataLonga
Copy link

Hi, i've don't have any experience on this kind of situation, and don't known if i'm allow to comment on this or not. Feel free, to delete my comment or ignore me.

I have one question, related to this (maybe), but what if "autoload" was in fact native on PHP without using "autoload" and "require_once" magic. What i'm trying to said, i love to see if we could use really native "imports" like java, or golang or c#, where we only need to use keyword already exists use Gravatalonga\MyLibrary;

Sorry if this is a dumb question or if isn't right place.
Cheers, and thanks for your hard work on PHP.
Have nice day!

@kamil-tekiela
Copy link
Member

@gravataLonga Hi. Generally, all discussion are on the mailing list. Please send all replies there.

Regarding your question, autoload is already native in PHP since version 5.0. I am not sure what you really meant. All classes can be loaded by just using them in code. No special includes are necessary. It's rare that you can eradicate includes completely from PHP code, but you definitely don't need them for classes.

@gravataLonga
Copy link

@kamil-tekiela sorry you can ignore me. Just following reply, i mean about autoload is for example, composer in order to autoload class, internally they make a include file.

// ./vendor/composer/ClassLoader.php

/**
 * Scope isolated include.
 *
 * Prevents access to $this/self from included files.
 */
function includeFile($file)
{
    include $file;
}

There aren't a native import class without first include file and them use use ... Class statement.

@iluuu1994
Copy link
Member

@markrandall Would you like to pursue this RFC?

@markrandall
Copy link
Author

Not for the time being, I abandoned it when Girgias started his wider re-write of the autoloading system to handle functions etc.

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

Successfully merging this pull request may close these issues.

None yet

8 participants