Traits and memory size

From: Date: Tue, 10 Apr 2012 01:34:38 +0000
Subject: Traits and memory size
Groups: php.internals 
Request: Send a blank email to internals+get-59593@lists.php.net to get a copy of this message
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.

« previous php.internals (#59593) next »