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.




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

Reply via email to