Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85861 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1986 invoked from network); 18 Apr 2015 15:08:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Apr 2015 15:08:07 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.178 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.217.178 mail-lb0-f178.google.com Received: from [209.85.217.178] ([209.85.217.178:35096] helo=mail-lb0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/22-12030-35372355 for ; Sat, 18 Apr 2015 11:08:07 -0400 Received: by lbbuc2 with SMTP id uc2so102454686lbb.2 for ; Sat, 18 Apr 2015 08:08:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=hfe9r3jJUvzXKnUW+ipwPjEOzNBGtfKTAY8Iy1eMLHI=; b=R1vUtv4JhUtu1FMBiAKW6TFETrToUH/uUPpcmbtRUWcpX6JxGgbQ2s1s/3wRpT5j2V jxmJNihLR+66yrzSkPKzWNc532RIJO3IK8woQHbMvx5X72ppK+73lVK2UGl+LVobPa3Y 6BHhcIrhUjPy0kjZUIjsAJnd4TCp+TtoUWXQqgFln7HvZ71KJ98eD1Osj7TYohy3DKXG OyVH/mk0QMbJMMrgILgUF2sznQW4DHODX2vq1bmPB4qinewymVPbre6cegujJZ3Z759x XDduGCz+6Q3cAYXz/v5Yzv3qLqXW3j6vw4UTTng0aqGgJx7x6X45ltAuSOLtUtab1cGD dZrg== MIME-Version: 1.0 X-Received: by 10.152.1.194 with SMTP id 2mr8678796lao.38.1429369681005; Sat, 18 Apr 2015 08:08:01 -0700 (PDT) Received: by 10.25.90.75 with HTTP; Sat, 18 Apr 2015 08:08:00 -0700 (PDT) In-Reply-To: References: Date: Sat, 18 Apr 2015 11:08:00 -0400 Message-ID: To: georges Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] RFC: spl_autoload_register() should provide kind of entity to load From: ircmaxell@gmail.com (Anthony Ferrara) Georges, On Sat, Apr 18, 2015 at 10:24 AM, georges wrote: > Hi php internals, > > Currently spl_autoload_register() pass the name of the class entity to the > first *Callable* argument, but there is now way (as i far i know) to know > what kind of entity we're looking for. > -Class ? > -Interface ? > -Trait? > > > A second argument should be added to the *Callable* function describing > what kind of entity we're looking for. > > Example: > > > // function __autoload($class) { > // include 'classes/' . $class . '.class.php'; > // } > > function my_autoloader($entity, $kind = "class") { > // Kind would be: class/interface/trait > include $kind . '/' . $entity . ".{$kind}.php"; > } > > spl_autoload_register('my_autoloader'); > > // Or, using an anonymous function as of PHP 5.3.0 > spl_autoload_register(function ($entity, $kind = "class") { > // Kind would be: class/interface/trait > include $kind . '/' . $entity . ".{$kind}.php"; > }); > > ?> > > > In fact i think currently that Autoload is too much "class oriented" as per > reading php docs, whereas that php currently allow the autoload of many > entities. It can really confuse probies php developers :( > > *Pros*: > > - -Avoid multiple else if() for testing an existing file to load the > entity. > - -As we now know the type of entity to load, it help reduce I/O > activity, then reduce timespend. > - -Clarify the code: We now what the autoloader will load > - -Keep the BC safe > > > *Cons*: > > - -None > This won't work out of the box due to spl_autoload(). If you use that default autoloader (by calling spl_autoload_register()), it will accept an optional second argument as the list of file extensions. Which means that having spl_autoload_register() pass a second argument to autoloaders will break the existing core autoloader. Changing the core autoloader is also not really possible due to BC considerations. So technically, without introducing a new autoload API, this won't really be possible. As far as the feature, I would question why you need to distinguish the file by the type. The names are in the same symbol table, so you couldn't possibly have a collision. From there, is the identification of the type of the definition in the filename that important? Isn't that just another form of Hungarian Notation? Anthony