On 08/08/2016 15:36, Levi Morrison wrote:
I feel like the problem here did not get across properly. Calling the
autoloader if a global function with the name exists will totally kill
performance. This means that every call to strpos() or any of the other
functions in the PHP standard library will have to go through the
autoloader first, unless people use fully qualified names (which,
currently, they don't). This is completely out of the question.
Interesting. I come to a different conclusion: this a great opportunity to
get developers to use the fully qualified names. Performance is an
incredibly motivating force even in many situations when it shouldn't be.
An example just to focus the mind:
namespace Lovely\New\Code;
class Blah {
function __construct(array $foo) {
foreach ( $foo as $item ) {
if ( strpos('blah', $item) !== 0 ) {
// ...
}
}
}
}
This will *repeatedly* call the function autoloader for
"Lovely\New\Code\strpos". The fully qualified name in this case is
"\strpos".
I think saying "add a backslash in front of your function names to avoid
them being slow" will just lead to lots of "lol wtf php sux".
If we wanted to make the \ mandatory, then the name resolution for
functions could have had no fallback, just like class names. The reasons
for having that fallback presumably still apply, so it doesn't make
sense to now declare it "broken by design, please avoid".
On the other hand, saying "you can autoload functions from another
namespace using qualified names or 'use function'" sidesteps the
fallback issue, and sounds like a reasonable, non-BC-breaking, feature.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php