These are my numbers:
Starting allocation 62480
Allocated memory for new A() 328
Allocated memory for new B() 496
Thus, x < y
These two class definitions are equivalent
class B extends A {
public $m = 1;
public $n = 2;
}
class C {
public $x = 5;
public $y = 6;
public $z = 7;
public $m = 1;
public $n = 2;
}
Assuming that if you changed the definition of B to the definition of C, then memory usage would be the same for using new B () or new C ().
, ( )
$start = memory_get_usage();
echo "Starting allocation $start\n";
$a = new A();
$diff = memory_get_usage() - $start;
echo "Allocated memory for new A() $diff\n";
$b = new B();
$diff = memory_get_usage() - $start - $diff;
echo "Allocated memory for new B() $diff\n";