Hi all,
This is (by my count) a 5th attempt at adding function autoloading to PHP.
- RFC: https://wiki.php.net/rfc/function-autoloading-five-oh
- PR: https://github.com/php/php-src/pull/22337
Looking forward to the discussion around this one!
-- pmj
Hey Paul,
Hi all,
This is (by my count) a 5th attempt at adding function autoloading to PHP.
- RFC: https://wiki.php.net/rfc/function-autoloading-five-oh
- PR: https://github.com/php/php-src/pull/22337
Looking forward to the discussion around this one!
-- pmj
What is the motivation to not do a second call to the function
autoloaders with "bar" (global namespace) when "bar()" is being called
in the Foo namespace and the initial call with "Foo\bar" doesn't resolve
to anything?
That would probably have much less rough edges, completely sidestepping
the issue here with Foo\bar() not being found.
Thanks,
Bob
Hi all,
This is (by my count) a 5th attempt at adding function autoloading to PHP.
- RFC: https://wiki.php.net/rfc/function-autoloading-five-oh
- PR: https://github.com/php/php-src/pull/22337
Looking forward to the discussion around this one!
-- pmj
I assume you saw my last attempt at this? :)
The general consensus was that spl autoloader needs to go and nobody wanted to see more added to it. That being said, maybe the list has changed its mind... hopefully.
— Rob
Hi all,
This is (by my count) a 5th attempt at adding function autoloading to PHP.
- RFC: https://wiki.php.net/rfc/function-autoloading-five-oh
- PR: https://github.com/php/php-src/pull/22337
Looking forward to the discussion around this one!
-- pmj
Hi Paul!
To make unqualified calls to
strlen()resolve to Foo\strlen() inside the Foo namespace, you must import the fully qualified function first
Imagine we have an old guzzle/psr7 with stream_for function, and they
use it without a qualifier. I defined a global stream_for so now I
hijacked the internal library logic. Is it correct?
The previous attempt with namespace pinning made more sense to me
--
Anton
Imagine we have an old guzzle/psr7 with stream_for function, and they use it without a qualifier. I defined a global stream_for so now I hijacked the internal library logic. Is it correct?
The previous attempt with namespace pinning made more sense to me
The concern that occurred to me is similar: if I rely on function autoloading, but forget to fully-qualify a name in the current namespace, it would accidentally work as long as some other code triggered loading of that function first. Then some small refactoring - or even a different path through the code at runtime - and it will silently fall back to a function in the global namespace instead.
I think if autoloading is going to require some extra "ceremony" in the code, it would be preferable to have a declare() at the top of the file forcing the interpretation of all unqualified names (either "always assume current namespace" or "always assume global namespace"). That way, code would not change behaviour based on hard-to-predict side effects elsewhere.
Rowan Tommins
[IMSoP]