In PHP, are objects methods code duplicated or shared between instances? <p>In PHP, if you make an array of objects, are the object methods (not data members) copied for each instance of the object in the array, or only once? I would assume that for memory reasons, the latter is true; I just wanted to confirm with the StackOverflow community that this is true.</p> <p>For example, suppose I have a class MyClass with a couple of methods, i.e.</p> <pre><code>class MyClass { public $data1; private $data2; public function MyClass($d1, $d2) { $this-&gt;data1=$d1; $this-&gt;data2=$d2; } public function method1() { } public function method2() { } } </code></pre> <p>Obviously in reality method1() and method2() are not empty functions. Now suppose I create an array of these objects:</p> <pre><code>$arr = array(); $arr[0] = &amp; new MyClass(1,2); $arr[1] = &amp; new MyClass(3,4); $arr[2] = &amp; new MyClass(5,6); </code></pre> <p>Thus PHP is storing three sets of data members in memory, for each of the three object instances. My question is, does PHP also store copies of method1() and method2() (and the constructor), 3 times, for each of the 3 elements of $arr? I'm trying to decide whether an array of ~200 objects would be too memory-intensive, because of having to store 200 copies of each method in memory.</p> <p>Thanks for your time.</p>