試すのが一番ですね。
lang
1<?php
2class Test1 {
3 private $test_no;
4 public function __construct() {
5 $this->test_no = 8;
6 }
7}
8class Test2 {
9 private $test_no = 8;
10 public function __construct() {
11 }
12}
13class Test3 {
14 private $test_no = 8;
15}
16
17
18$start = microtime();
19for ( $i = 0; $i < 10000; $i++ ) {
20 $test = new Test1();
21}
22$end = microtime();
23echo $end-$start,"\n";
24
25$start = microtime();
26for ( $i = 0; $i < 10000; $i++ ) {
27 $test = new Test2();
28}
29$end = microtime();
30echo $end-$start,"\n";
31
32$start = microtime();
33for ( $i = 0; $i < 10000; $i++ ) {
34 $test = new Test3();
35}
36$end = microtime();
37echo $end-$start,"\n";
38?>
私の環境ではこうでした。
0.031074
0.02288
0.010054
基本はシンプルな方が処理効率が高くなります。
ただ、引数などで設定する値が決まる場合はコンストラクタが必要ですね。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。