> -----Original Message-----
> From: Ben Schmidt [mailto:mail_ben_schm...@yahoo.com.au] 
> Sent: 10 April 2012 02:35
> To: internals@lists.php.net
> Subject: [PHP-DEV] Traits and memory size
> 
> Hi!
> 
> Just a quick question about traits.
> 
> During the flattening process, is a copy made of the trait 
> code (or bytecode or whatever)?
> 
> So, if I have
> 
> trait A {
>     // a bunch of methods
> }
> class B {
>     use A;
> }
> class C {
>     use A;
> }
> class D {
>     use A;
> }
> 
> will I have four copies of A because it has been copied into 
> all of the classes, and thus this aspect of my code will take 
> up four times as much memory than if I did:
> 
> class A {
>     // a bunch of methods
> }
> class B extends A {
> }
> class C extends A {
> }
> class D extends A {
> }
> 
> Or is the code shared so the memory use will be roughly the same?
> 
> I realise the use cases for traits and inheritance are 
> different, and often the situation will dictate the design, 
> but sometimes you have these two options so have to make a 
> design decision, and it would be nice to know the impact on 
> memory use/code size.
> 
> Hope this is a simple question and won't take too much time 
> for anyone to answer!
> 
> Thanks!
> 
> Ben.
> 

I don't know the answer to your question. 

But the decision to use traits or inheritance should be pretty
obvious, and the amount of memory either way uses should be
irrelevant. 
If either choice appears to be allocating too much, then it's the Zend
Engine itself that should be looked at, and not rewritting PHP code.

Jared


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to