Re: autoload with namespace

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Apr 1, 2008 at 8:28 PM, Ryan Panning <rpanning@xxxxxxxxx> wrote:

> I haven't been keeping an eye on this list so if this has come up before
> please point me in the right direction. :)
>
> Playing around with dev PHP 5.3 and namespaces, I'm finding it hard to
> write an autoload function. Since autoload will be triggered on any
> namespace call, the request could be for a namespace function or constant.
> Ex:
>
> FOO::BAR::me() ## A namespace function or class static function?
> FOO::BAR::ME   ## A namespace constant or class constant?
>
> Since there isn't really a way for PHP to know what it is looking for,
> what would be a good method to write the autoload? Assuming the file
> structure:
>
> - Namespaces are in separate directories NS1::NS2::Class1 ==
> NS1/NS2/class.Calss1.php
> - Namespace files and class files are prefixed with ns.*.php and
> class.*.php (respectively)


i havent gotten the chance to work w/ 5.3 yet (been burried  w/ other crap
lately)  anyways ive been wondering about an autoloader in 5.3 so this is a
cool thread ;)  well i would probly just extend my mechanism for pre-5.3 and
that is essentially to populate an array of absolute paths to your files.
in ur case each path would map directly to a package followed by the class
that contains it.   so then ur autoloader just looks at the mapping when a
request comes in, checks the appropriate index in this array and calls
require or w/e on the abs path.

there is one curiosity / caveat underlying the 5.3 implementation...  so
does the namespace get supplied to the autoload function as well as the
class name?  is it just one big string or are they separate?

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux