Re: Function auto-loading
| From: | Rowan Collins | Date: | Tue, 09 Aug 2016 21:15:18 +0000 |
| Subject: | Re: Function auto-loading | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-94979@lists.php.net to get a copy of this message | ||
On 09/08/2016 21:26, Fleshgrinder wrote:
An alternative approach could be to auto-load only namespaced things and leave non-namespaced stuff alone.It's not quite as simple as that, as examples have already shown. # file a.php namespace Acme\Foo; function a() {
return 'Hello World';} # file b.php namespace Acme\Foo; function b() {
$message = a(); # this is a call to Acme\Foo\a
return strpos($message, 'Hello'); # this is a call to \strpos
}
There's no way of telling that the a() is namespaced and the strpos() is global until *after* the autoloader has run. There *might* be a function Acme\Foo\strpos which is autoloadable.
Regards,
--
Rowan Collins
[IMSoP]