Re: Not autoloading functions
| From: | Fleshgrinder | Date: | Fri, 20 Jan 2017 19:30:44 +0000 |
| Subject: | Re: Not autoloading functions | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-97899@lists.php.net to get a copy of this message | ||
On 1/20/2017 7:58 PM, Nikita Popov wrote:
> On Fri, Jan 20, 2017 at 7:55 PM, Stanislav Malyshev <smalyshev@gmail.com>
> wrote:
>
>> Hi!
>>
>>> Since the autoloading functions proposal is stalled, how about allowing
>> for
>>> import of static functions instead?
>>>
>>> use function Foo::bar;
>>>
>>> bar(); // calls Foo::bar()
>>
>> I'm not sure why it is good. This would certainly be confusing, if you
>> call strlen and turns out it's completely different function from what
>> you thought. One thing when it's the same namespace, at least you can be
>> aware what this package does, but if it's just an arbitrary function
>> from anywhere, it's really bad for understanding the code.
>>
>
> How is that different from the already existing "use function foo\bar\baz
> as strlen"?
>
Or any other function that has no namespace separator in front.
```
<?php
namespace Fleshgrinder\Examples;
function strlen($string) {
return 42; // Troll! =)
}
final class SomeClass {
public function __construct() {
echo strlen('f');
}
}
new SomeClass;
```
This is actually used by some in tests to provoke error conditions in
built-in PHP functions to verify their error handling.
--
Richard "Fleshgrinder" Fussenegger