這是我的號碼:
Starting allocation 62480
Allocated memory for new A() 328
Allocated memory for new B() 496
因此x < y
這兩個類定義是等價的
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;
}
也就是說,是你改變B的定義成的C則內存使用情況與使用新的B()或新的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";
吹毛求疵:它更像是「'$ B' *是*的A,但更多的東西」比「有一個內部的實例」。 :) – deceze 2009-12-14 08:33:29