Hi all,
I am still fairly new to PHP so if this is a silly question please don't bite my head off. :)
Is there a significant performance hit for having multiple autoloaders registered?
I was thinking of having three autoloaders in a application and was wondering if it would cause problems. The first one would be the app autoloader which would load the classes specific to that application, then there would be a core autoloader for the core classes, and finally there would be composer for third party packages.
Does that make sense at all or am I off my rocker?
I am thinking that it would allow the app classes to override the core classes, which would in turn override the third party pack.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
However...I really do like the idea of a packaging and loader standard, if it was built around the capability of the phar to reach into .tgz archives and load files. So you could have:-/path/to/packages/foo-bar.tgzI think this would also require some collaboration with IDE makers to allow autocomplete, code hinting, etc to also look into them.
** Note ** I am not a voting member, just my 2 bits worth.1.) I like the idea of removing the legacy elements from PSR-0. But perhaps this should be discussed under some system of maintaining and updating the existing PSR's. (Perhaps a PSR-0.2014?, but should probably be discussed elsewhere)2.) I don't see the need to add the additional complexity, essentially replacing the legacy stuff you are removing, with something else, just for a shallower dir structure.Using your example of "\Foo\Bar\Dib\Zim" being located in "/path/to/packages/foo-bar/src", am I correct in interpreting that as:-Foo = Vendor nameBar = PackageDib\Zim = Namespace\Class?If so, what happens when I have multiple packages from the same vendor? Surly I end up with:-/path/to/packages/foo-bar/src/path/to/packages/foo-baz/srcinstead of:-/path/to/packages/foo/bar/src/path/to/packages/foo/baz/srcThus breaking the whole concept of a directory structure altogether!
Personally, I would prefer a few "empty" directory levels, and a much simpler and standardised autoloader spec, than the complexity of mapping prefixes to parts of a namespace.
However...I really do like the idea of a packaging and loader standard, if it was built around the capability of the phar to reach into .tgz archives and load files. So you could have:-/path/to/packages/foo-bar.tgzI think this would also require some collaboration with IDE makers to allow autocomplete, code hinting, etc to also look into them.
Unqualified name:
This is an identifier without a namespace separator, such as Foo
Qualified name:
This is an identifier with a namespace separator, such as Foo\Bar
Fully qualified name:
This is an identifier with a namespace separator that begins with a
namespace separator, such as \Foo\Bar. The namespace \Foo is also a
fully qualified name.Qualified name, they do not ever receive a class name prefixed with a \. So new \Foo\Bar is converted to a Qualified name and PHP will send Foo\Barto the autoloader.However, in the interest of using standardized language, I can see a case for using the above terms, and changing the code examples to strip a leading backslash (even though it might not be there) to emphasize the idea that what it's receiving is what we've been calling an absolute class name.
Well, call me biased but in this age of composer usage I don't reallysee a big point to reinvent such a commodity. The only valid argument
IMO might be specific performance requirements.
Anyway even if you count framework implementors and whatever, it's still
not something that many people really need to do.. and again if they do
I'd rather not have them copy paste it from the spec, because if they
build sometihng general purpose most likely they're going to share it.
You might not see the point, but others (for whatever reason) might be unwilling or unable to use Composer. Having a general-purpose example remains useful to those folks, whoever they might be. Indeed, I'd argue that if there's to be one example only, it should be the general-purpose one.
<https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md>
1. I agree it is a bad idea to "abandon" PSR-0 (if that is even possible).So many projects have jumped on it, killing it would "make a lot of people very angry and be widely regarded as a bad move".
Still I do strongly support PSR-X.This means, we will be living in a world where PHP developers need to learn both patterns.
It might be easier to learn if you don't have to care about the underscore, but then you still have to learn PSR-0 anyway, which eliminates the advantage.
4. Having one pattern with the fancy underscore logic (PSR-0) and another without (PSR-X) will feel awkward, and
5. it will make it harder to reuse the same class loader for both.
So, I would propose to keep the underscore logic from PSR-0, and only introduce the shallow directories.
This will make it easy to support PEAR, PSR-0 and PSR-X all in the same autoloader implementation. If implemented in a decent way, this will give us a measurable performance benefit over having separate class loaders for different packages. (besides, one shared autoloader can also have one shared cache mechanic)
I'm not even sure what deprecating PSR-0 would mean in this context. It
effectively means a de facto "vote of no confidence" in PSR-0, since we
cannot and should not "remove" PSR-0. It will always be there; it's
just a matter of what we talk about at conferences. :-)
As I noted before, PSR-X is a superset of PSR-0 iff none of your classes
contain underscores. Are we willing to as a group say "we're breakin'
ur underscores if you want to stick to 'active' specs"?
Before you knee-jerk respond "well duh, WTF are you doing not using
namespaces yet?" keep in mind there are two very important and
influential projects that still use PHP 5.2 and underscores that would
be incompatible with PSR-X: PHPUnit and Twig. Deprecating PSR-0 while
PSR-X still removes the BC handling would be effectively saying "PHPUnit
and Twig, FIG officially tells you to piss off."
Noooooooo! Why would we want this? We're trying to remove this silly naming oddity. Underscores are not used by modern Zend/Symfony code, even Kohana is ripping it out I believe.
This will make it easy to support PEAR, PSR-0 and PSR-X all in the same autoloader implementation. If implemented in a decent way, this will give us a measurable performance benefit over having separate class loaders for different packages. (besides, one shared autoloader can also have one shared cache mechanic)Why not just use Composer or PHPab instead of forcing PSR-0 to maintain backwards compatibility with one of its biggest bugs and annoyances?
Hi all,
Several changes to the proposal have been committed and pushed, which is still found here:
<https://github.com/php-fig/fig-standards/blob/master/proposed/package-oriented-autoloader.md>
- There are various changes to the code examples; in particular, the general-purpose code example has been expanded to include the optional "multiple directories per namespace" functionality noted in the spec.
if (! isset()) this is something we specifically ommitted from the coding standard because there was so much disagreement. To use it in a code example creates a precedent and will only lead to more confusion and endless discussion on the list from confused users. Was there so much disagreement? I don't recall seeing it on the list. What was the particular issue?
Besides the discussion of these changes, I do not recall any unresolved issues. (Please correct me if I'm wrong.)
Comments/questions/critique?
https://github.com/php-fig/fig-standards/wiki/Further-Style-Guide-Considerations
Mailing list link here:
https://groups.google.com/forum/?fromgroups=#!topic/php-fig/TRpoq0kdrZk
There was discussion in a PR or issue as well. Can't remember if it is linked in that thread or not. By linking these I do not mean to imply I'm personally happy with the current resolution/workaround. :)
this is something we specifically ommitted from the coding standard because there was so much disagreement. To use it in a code example creates a precedent and will only lead to more confusion and endless discussion on the list from confused users.
On 24 May 2013 18:09, Phil Sturgeon <em...@philsturgeon.co.uk> wrote:Noooooooo! Why would we want this? We're trying to remove this silly naming oddity. Underscores are not used by modern Zend/Symfony code, even Kohana is ripping it out I believe.Phil, while it may be an oddity, no-one seriously tries to name a class Test\Package\Foo_Bar_Bazso pedantically sure, it's an oddity, but it's no no practical relevance surely!
We cannot deprecate PSR0 because PEAR classnames are a very valid part of the PHP ecosystem. PSR-X fails in this respect. There are a lot of 1st class projects that use PEAR class names and which will not be refactored to PHP 5.3 namespace, like Twig because there is no benefit to refactoring to namespaces.
Co-existence and deprecation is pretty much the same thing, with the only real difference being wether we suggest one thing, or two things. If we suggest two things, then why exactly are we suggesting both of them? Is it just for these underscore using projects? Keeping PSR-0 as an active recommended standard just to avoid suggesting "Hey PEAR, Twig, etc, you should probably one day consider updating to use namespaces." to me seems like a weak reason.
Hi all,
For what it's worth, I intend to re-submit the package-oriented autoloader proposal this coming Friday. If you have fixes or suggestions, now is the time to bring them up.
I have gone back and looked through the emails that appear to have constructive criticism regarding the proposal. The only item of note that I found was from André Romcke, which I have cobbled together from different messages. (André, please correct me if the removal of context changes your meaning.)
> Imo the spec / interface should define what should happen if you get a namespace match but missing file in that namespace, otherwise we push the ambiguity down on implementers / users. And to me, a base system like a autoloader should never cause slow downs by design, so a match not existing on disk should throw a exception, either custom one or something like Logic-/Runtime-Exception.
>
> ...
>
> Basically just returning false if file is not found in matching namespace, allowing other autoloaders in the chain to try as well, something which is not possible with exceptions.
>
> ...
>
> If needed, fix is simple, as proposed before on this list, add a flag for what to actually do on a false match can include the following options:
>
> - NS_MATCH_NO_FILE_EXCEPTION
> - NS_MATCH_NO_FILE_RETURN
> - NS_MATCH_NO_FILE_IGNORE / CONTINUE
I take this to mean that we should specify what happens if an autoloader implementation fails to find the file for a class. There are two considerations to keep in mind:
1. Most of the time an autoloader should not get in the way of other autoloaders when it can't find a file, e.g. by throwing exceptions.
2. Sometimes an autoloader expects to be the last resort, and the implementor wants it to throw an exception when it can't find a file.
As such, I think it's reasonable to add a line to the spec, but using optional language, to indicate that the normal course is to stay out of the way, but that it is allowed if necessary.
- "Exceptions SHOULD NOT be thrown, and errors SHOULD NOT be raised, in the case of a missing file."
The wording is clumsy and probably not broad enough. Thoughts?
-- pmj
On 05/20/2013 04:50 PM, Paul Jones wrote:
> On May 20, 2013, at 6:30 PM, Amy Stephen wrote:
>
>> Seems that there is at least some support for superseding PSR-0. I hope that is considered. In the end, I think that will be least confusing and the easiest moving forward.
> /me nods
>
> I admit, I am uneasy about replacing and deprecating PSR-0.
>
> Anyone else?
>
>
> -- pmj
I'm not even sure what deprecating PSR-0 would mean in this context. It
effectively means a de facto "vote of no confidence" in PSR-0, since we
cannot and should not "remove" PSR-0. It will always be there; it's
just a matter of what we talk about at conferences. :-)
As I noted before, PSR-X is a superset of PSR-0 iff none of your classes
contain underscores. Are we willing to as a group say "we're breakin'
ur underscores if you want to stick to 'active' specs"?
Before you knee-jerk respond "well duh, WTF are you doing not using
namespaces yet?" keep in mind there are two very important and
influential projects that still use PHP 5.2 and underscores that would
be incompatible with PSR-X: PHPUnit and Twig. Deprecating PSR-0 while
PSR-X still removes the BC handling would be effectively saying "PHPUnit
and Twig, FIG officially tells you to piss off."
On Tuesday, May 21, 2013 1:08:32 AM UTC+2, pmjones wrote:
...
2. Sometimes an autoloader expects to be the last resort, and the implementor wants it to throw an exception when it can't find a file.
@pmjones: The spec seems to be missing "Vendor Name" part, that and potential other missing pices from PSR-0 should probably be re-added if this in the end officially supersedes/deprecates PSR-0.
How about:
- "The registered autoloader callback MUST NOT throw exceptions, SHOULD NOT raise errors of any level, and MAY return a value."
On 24 May 2013 18:09, Phil Sturgeon <em...@philsturgeon.co.uk> wrote:Noooooooo! Why would we want this? We're trying to remove this silly naming oddity. Underscores are not used by modern Zend/Symfony code, even Kohana is ripping it out I believe.Phil, while it may be an oddity, no-one seriously tries to name a class Test\Package\Foo_Bar_Baz
Ok, it seems I am quite alone with my point of view.So I will try to make my point clear enough, but I am prepared to let it drop and get over it and stop bothering you.
On Friday, May 24, 2013 11:33:29 PM UTC+2, Drak wrote:On 24 May 2013 18:09, Phil Sturgeon <em...@philsturgeon.co.uk> wrote:Noooooooo! Why would we want this? We're trying to remove this silly naming oddity. Underscores are not used by modern Zend/Symfony code, even Kohana is ripping it out I believe.Phil, while it may be an oddity, no-one seriously tries to name a class Test\Package\Foo_Bar_BazSeems that is the general consensus, although I don't fully agree with it.
-- pmj
The other approach, in order to allow PEAR class names to load would be to specify a namespace character so you can specify \ (the default) or _ when registering the namespace. e.g.
public function addNamespace($namespace, $path, $separator = '\\')
How about:
- "The registered autoloader callback MUST NOT throw exceptions, SHOULD NOT raise errors of any level, and MAY return a value."
Further thoughts?
The other approach, in order to allow PEAR class names to load would be to specify a namespace character so you can specify \ (the default) or _ when registering the namespace. e.g.
public function addNamespace($namespace, $path, $separator = '\\')Now this is an interesting approach, what would be the downside of allowing a "registering package" to specify their NS separator? I realize PHP already gave us a namespace separator and that we should be using it, but I don't see a downside to this. It allows PEAR packages to be PSR-X and (somewhat) satisfies the naysayers.
There will of course be some folks trying to load \Vendor\Package\Class_Name and expect _ to equal = as well as \. I imagine \ will ALWAYS act as \ in all situations, and the "separator" is just another character which will also map to /.
Having said that, if this becomes something that we think has way more positives than negatives, it should be limited to *only* the specified separator. I.e., there should be no allowance for mixing different separators in a single fully-qualified class name. You get *either* Foo\Bar\Baz\Qux, *or* Foo_Bar_Baz_Qux, but not Foo\Bar\Baz_Qux.
-- pmj
-- pmj
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/41BC323D-59CD-4545-BF0C-60FA811FBFAF%40gmail.com?hl=en.
I'm not sure we would have to go that route. Since Foo_Bar_Baz_Qux is the "fully qualified class name", we could still relegate the underscore to only effect the class name part of the namespace. This would retain BC with PSR-0 since underscores don't effect any part of the namespace, and would allow for PSR-0 to fit within PSR-X. While that's not a stated objective, I think it is a notable benefit.
-- pmj
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/8708C8D2-BAA5-4097-A666-50711FC8554E%40gmail.com?hl=en.
This sounds good, as it aligns with the default autoloader, spl_autoload().
About the error guarantee, are there any use cases where it makes sense for an autoloader to throw a hard error, i.e. E_USER_ERROR/E_ERROR?As I understand it, an autoloader is strictly to fail gracefully, for the fallback chain to make sense.The only case where I could think about raising an error would be a corrupt PHAR, but should that be handled at the autoloader level?
"The registered autoloader callback MUST NOT throw exceptions, SHOULD NOT raise errors of any level, and MAY return a value."The last messages I read showed two objections:
- André Romcke believed it was not specific enough, and wanted to limit it only to cases when the file could not be found in a registered namespace. (I and at least one other believe it is broad enough to cover Andrés case as well as other cases.)
- Peter Cowburn believed the "MAY return a value" clause is unnecessary. (I and at least one other think it's good to point out that returned values are a reasonable occurrence.)
Does anyone continue to have strong feelings regarding the new spec item?
It may not be *necessary* to return a value for testing, but it can be *useful* to return a value for testing. (Indeed, it is in fact useful, since the tests I have for a modified general-purpose autoloader make use of a return value to see which file got loaded.)
"The relative class name MUST be mapped to a sub-path by replacing namespace separators with directory separators, and the result MUST be suffixed with .php."Should this section take into account this PHP RFC - https://wiki.php.net/rfc/phpp
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/747d7007-e264-4074-8c43-65d01f9121c5%40googlegroups.com?hl=en.
> Is it just me, or does that RFC "solve" a problem that simply does not exist?
Whether it does or doesn't, it's a bridge that can be crossed later.