Kurucu dışındaki özelliklerin başlatılması avantajı, kodunuzu okuyan birinin hemen varsayılan değerini bilmesidir.
Her türlü veriyi bu şekilde kullanamazsınız - örneğin, ne olduğunu hatırladığımdan, örneğin, veya sözdizimi sözdizimi ile, nesne instanciations ile çalışmayacaksınız. Neyse, muhtemelen uygulamanın ;-)
yılında, daha çok bir önemi çok şeyler vardır - bu performansa gelince kadar fark var sanmıyorum
Yine de, sadece eğlence için, Vulcan Mantık Disassembler kullanarak:
<?php
class TestClass {
private $test_var = 'Default Value';
function __construct() {
}
}
$a = new TestClass();
: kodunun ilk örnek (temp-2.php
) ile
<?php
class TestClass2 {
private $test_var;
function __construct() {
$this->test_var = 'Default Value';
}
}
$a = new TestClass2();
Siz bu işlem kodları almak: Yani
$ php -d extension=vld.so -d vld.active=1 temp-3.php
Branch analysis from position: 0
Return found
filename: /home/squale/developpement/tests/temp/temp-3.php
function name: (null)
number of ops: 11
compiled vars: !0 = $a
line # op fetch ext return operands
-------------------------------------------------------------------------------
2 0 EXT_STMT
1 NOP
8 2 EXT_STMT
3 ZEND_FETCH_CLASS :1 'TestClass2'
4 EXT_FCALL_BEGIN
5 NEW $2 :1
6 DO_FCALL_BY_NAME 0
7 EXT_FCALL_END
8 ASSIGN !0, $2
9 9 RETURN 1
10* ZEND_HANDLE_EXCEPTION
Class TestClass2:
Function __construct:
Branch analysis from position: 0
Return found
filename: /home/squale/developpement/tests/temp/temp-3.php
function name: __construct
number of ops: 7
compiled vars: none
line # op fetch ext return operands
-------------------------------------------------------------------------------
4 0 EXT_NOP
5 1 EXT_STMT
2 ZEND_ASSIGN_OBJ 'test_var'
3 ZEND_OP_DATA 'Default+Value'
6 4 EXT_STMT
5 RETURN null
6* ZEND_HANDLE_EXCEPTION
End of function __construct.
End of class TestClass2.
, orada tahmin ediyorum
$ php -d extension=vld.so -d vld.active=1 temp-2.php
Branch analysis from position: 0
Return found
filename: /home/squale/developpement/tests/temp/temp-2.php
function name: (null)
number of ops: 11
compiled vars: !0 = $a
line # op fetch ext return operands
-------------------------------------------------------------------------------
2 0 EXT_STMT
1 NOP
7 2 EXT_STMT
3 ZEND_FETCH_CLASS :1 'TestClass'
4 EXT_FCALL_BEGIN
5 NEW $2 :1
6 DO_FCALL_BY_NAME 0
7 EXT_FCALL_END
8 ASSIGN !0, $2
9 RETURN 1
10* ZEND_HANDLE_EXCEPTION
Class TestClass:
Function __construct:
Branch analysis from position: 0
Return found
filename: /home/squale/developpement/tests/temp/temp-2.php
function name: __construct
number of ops: 4
compiled vars: none
line # op fetch ext return operands
-------------------------------------------------------------------------------
4 0 EXT_NOP
5 1 EXT_STMT
2 RETURN null
3* ZEND_HANDLE_EXCEPTION
End of function __construct.
End of class TestClass.
While kod ikinci örnekte (temp-3.php
) ile: Bu işlem kodları almak Bir fark biraz ... Ama bu önemli değil ^^
Opcodes yorumlamak size kalmış - - ama komik şey aslında ^^
:-(Zaten varsayılan adres VLD (ya da sadece değil) her şeyi terk edemezsin görünüyor ... İlk çöplükte '
Default Value
' hiçbir iz yoktur ilginçtir değer ... onlara TEKRAR ALMAK gerek yok. –