On Mon, Aug 8, 2016 at 10:54 PM, Lester Caine <les...@lsces.co.uk> wrote:
> I can understand a little the overwhelming desire to wrap everything in
> it's own set of name spaces, but is that REALLY essential to make PHP
> 'work better'. What is wrong with a simple 'include_once' of the library
> you want to use globally across all the code?

Doesn't work with Composer packages, because you can't (and aren't
supposed to) know where a package is installed.

That is, when I'm running the test-suite of my package, the Composer
project is the root folder of that package - but when the package is
being consumed by another project, it's installed in a sub-folder in
that project's "vendor" folder.

The whole point of auto-loading is you don't need to know where things
are installed - a class will simply auto-load, regardless of whether
or not the package is the root project package of the consuming
package. Composer takes care of the bootstrapping.

If we didn't care about that, we wouldn't need auto-loading at all. Or
in other words, your argument works against auto-loading of functions
and classes equally.

What's wrong with a simple require/include statement when you need a
class? Nothing per se. It's horribly inconvenient. The main reason
you're not feeling the same inconvenience when it comes to functions,
is likely because you avoid using them - which is likely because using
functions isn't practical. Likely because they don't auto-load, like
functions. So we use classes as pseudo-namespaces, because they can
auto-load - but that's not what classes are for; you could just as
well argue the language shouldn't have functions at all, then.

In a nut-shell: functions are inconvenient because they don't
auto-load, so we don't use functions, so we don't need auto-loading;
but that's a circular argument.

Of course we need functions to auto-load. For all the same reasons we
need classes to auto-load. Nobody wants to stop and have to figure out
in which file a function is located before they can call it, anymore
than they want to do so for classes. Nobody wants breaking changes in
50 different files because they renamed a file or decided to
split/join some functions across some files.

The auto-loading requirement for functions is the same as for classes.
There's no difference.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to