I know PHP will only copy data if necessary. So, in this code:
$a = 'HELLO WORLD';
$b = $a;
$b = $b . '!';PHP never took the time to copy the ‘HELLO WORLD’ string until line 3. However, what about multiple instances of the same class? If I have:
class hworld {
var $c;
public function meth() {
$c = 'HELLO WORLD!';
}
}and later I run:
$foo = new hworld();
$bar = new hworld();
$bar->meth();Now I clearly have two values of $c. My question is: PHP clearly has to make a copy of the object—but does it also make a (seemingly useless) copy of the meth() method?
I’m only curious for the purpose of writing good code. I hope it doesn’t, but if it does I’d like to know to avoid many copies of classes with large methods.
Thoughts? Am I misunderestimating PHP?