Autoloading traits

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Autoloading traits

Roediger, Tim

So I’ve started playing around with traits, but they don’t seem to autoload. If I add them by hand to the autoload_classmap.php is all good (the classmap_generator ignores them), but is there another simpler way to do it?

 

Tim Roediger

Reply | Threaded
Open this post in threaded view
|

Re: Autoloading traits

leedavis
This post has NOT been accepted by the mailing list yet.
I ran a small test with PHP 5.4.3, it appears PHP will call on registered autoloaders to load traits.

With mytrait.php as:
------------------
trait mytrait
{
    function foo()
    {
        echo 'bar';
    }
}
------------------

I ran loadtrait.php:
-----------------------------------------------
function myAutoloader($name)
{
    echo 'Attempting to load resource for ' .  $name;
    require $name . '.php';
}
spl_autoload_register("myAutoloader");

class Test
{
    use mytrait;
}

$test = new Test();
$test->foo();
-----------------------------------

Which outputs:

"Attempting to load resource for mytrait
bar"

So as long as the registered autoloader(s) supports them, they should load ok.
Reply | Threaded
Open this post in threaded view
|

Re: Autoloading traits

weierophinney
Administrator
In reply to this post by Roediger, Tim
-- Tim Roediger <[hidden email]> wrote
(on Thursday, 10 May 2012, 06:01 AM +0000):
> So I’ve started playing around with traits, but they don’t seem to autoload. If
> I add them by hand to the autoload_classmap.php is all good (the
> classmap_generator ignores them), but is there another simpler way to do it?

We should modify the classmap generator to also look for the trait token
-- could you raise an issue in the tracker for this, please?

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Reply | Threaded
Open this post in threaded view
|

Re: Autoloading traits

Antoine Hedgecock
I have no problems with traits autoloading 

Best regards
Antoine Hedgecock 
Senior developer / Server technician
PMG Media Group AB
Tel: +46707962145

On May 10, 2012, at 3:19 PM, Matthew Weier O'Phinney wrote:

-- Tim Roediger <[hidden email]> wrote
(on Thursday, 10 May 2012, 06:01 AM +0000):
So I’ve started playing around with traits, but they don’t seem to autoload. If
I add them by hand to the autoload_classmap.php is all good (the
classmap_generator ignores them), but is there another simpler way to do it?

We should modify the classmap generator to also look for the trait token
-- could you raise an issue in the tracker for this, please?

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

Reply | Threaded
Open this post in threaded view
|

RE: Autoloading traits

Roediger, Tim

I’ve raised an issue in the tracker against Zend\Loader to update the classmap_generator.

 

In regard to the other comments about traits autoloading, I’ll look into it more. Clearly there is something I’m not doing right.

 

Tim Roediger

 

From: Antoine Hedgecock [mailto:[hidden email]]
Sent: Friday, 11 May 2012 2:08 AM
Cc: [hidden email]
Subject: Re: [zf-contributors] Autoloading traits

 

I have no problems with traits autoloading 

 

Best regards

Antoine Hedgecock 

Senior developer / Server technician

PMG Media Group AB

Tel: +46707962145

 

On May 10, 2012, at 3:19 PM, Matthew Weier O'Phinney wrote:



-- Tim Roediger <[hidden email]> wrote
(on Thursday, 10 May 2012, 06:01 AM +0000):

So I’ve started playing around with traits, but they don’t seem to autoload. If

I add them by hand to the autoload_classmap.php is all good (the

classmap_generator ignores them), but is there another simpler way to do it?


We should modify the classmap generator to also look for the trait token
-- could you raise an issue in the tracker for this, please?

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc