I'm sure the internal coders will correct me if I'm wrong on this, but as I
understand it PHP has no notion of packages, yet many calls to modify how
namespace importing works seem to be under the illusion that packages
exist. This is understandable, packages are namespaces are terms used
somewhat interchangeably. However, they aren't the same.  In Java,
Actionscript 3, and I presume C++ and C# when you import a package you are
binding it to the resultant executable the compiler will create. This will
affect the size of that executable regardless of how much of the package
gets used, or even if it gets used.

PHP has packages, but they are compiled in when the interpreter is compiled
and set up on the machine. Adding a package in PHP requires redoing that
compile step and modifying the php.ini to enable the associated .so file.
As for libraries looked up by composer - these are never referenced until
they are called for at runtime and the autoloader gets invoked.

As a result of this PHP's "namespace" resolution is nothing more than a set
of string replace rules done at call time to try to resolve the name to a
known class. It's a convenience shorthand for programmers, but a powerful
one. Also, it has it's limitations.

On Fri, Nov 24, 2017 at 8:21 AM, Rowan Collins <rowan.coll...@gmail.com>
wrote:

> On 24 November 2017 07:05:52 GMT+00:00, "Khawer ." <khaweronl...@gmail.com>
> wrote:
> >We use 'use' keyword to import other namespaces, namespace classes,
> >namespace functions, and namespace constants.
> >
> >Example
> >1) use abc; (Import abc namespace)
> >2) use abc\ClassB; (Import ClassB  from abc namespace)
>
> Although these are described in the manual as separate types of import,
> they are actually the same: they alias a prefix used to rewrite class names
> when you mention them.
>
> If you have a class "One\Two\Test" and a class "One\Two", then "use
> One\Two" will allow you to access them as "Two\Test" and "Two",
> respectively. https://3v4l.org/nQ7pB
>
> Similarly, if you alias a prefix with "use Foo as Bar", then "new
> Bar\Test" will refer to class "Foo\Test", and "new Bar" will refer to class
> "Foo". https://3v4l.org/2r6WN
>
> So "use class" wouldn't make sense, because that's not actually what
> happens.
>
> Regards,
>
> --
> Rowan Collins
> [IMSoP]
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to