I'm not talking about the __call() magic method, I'm proposing a global
and/or namespaced call to a flat __call() *function *- you could use it to
implement autoloading like so:
*
*
<?php

function __call($name, $arguments)
{
  $path = str_replace('\\', DIRECTORY_SEPARATOR, $name);
  require FUNC_PATH . DIRECTORY_SEPARATOR . $path;
  return call_user_func_array($name, $arguments);
}
*
*Since the introduction of namespaces, functions are really more like
"static methods" of the namespace; they're no different from static methods
of a class, really.

If you wanted to autoload methods in class for some reason, you can already
do that - using the __call() magic method, a method-table (array where
method-name => closure) and loading scripts that return an anonymous
function.

Similarly, we could use a namespace-specific __call() function as shown
above, to autoload functions.

It was just a thought - just throwing it out there for discussion, I'm not
submitting a complete RFC at this point :-)

/ Rasmus Schultz


On Sun, Aug 14, 2011 at 6:44 PM, Ferenc Kovacs <tyr...@gmail.com> wrote:

> On Mon, Aug 15, 2011 at 12:11 AM, Rasmus Schultz <ras...@mindplay.dk>
> wrote:
> > Instead of trying to figure out how to autoload functions and cover all
> your
> > bases, how about simply adding a __call() magic method?
> >
> > That way, each application (or framework) can make their own decisions
> about
> > what they're going to autoload and how.
> >
> > A much simpler solution, and one with more potential uses than just
> > autoloading.
> >
> > The __call() method could be invoked first in the current namespace, if
> > present - then in the parent namespace, if present, etc. up to the global
> > namespace. Since functions are no longer just global, but can now exist
> in a
> > namespace, it is likely you're going to need a different "autoloader" or
> > other dynamic function resolvers in each namespace, since we tend to
> create
> > a namespace for classes/functions designed to perform a specific kind of
> > task - for example, a template/view-engine probably needs to autoload
> > display-formatting functions, while a controller/dispatcher might need to
> > autoload action-filters, etc.
> >
> > Just a thought :-)
> >
> > / Rasmus Schultz
> >
>
> we already have a magic method with the name __call.
> I'm not sure where you propose adding this magic method, but judging
> from it's name, you would like to propose something similar than
> __autoload what we have abadoned for many reasons, the main reasons is
> that the spl_autoload_register is more explicit and supports having
> multiple callbacks.
>
> please create an RFC for your idea, from first glance, I feel that you
> didn't really thought over the details yet.
>
>
> --
> Ferenc Kovács
> @Tyr43l - http://tyrael.hu
>

Reply via email to