Witam,
tak się zastanawiam jaka jest wyższość klas/metod instancyjnych nad statycznymi. Czy ma ktoś dobry przykład że lepiej zastosować gdzieś klasę/metodę instancyjną niż statyczną? Bo chyba wszystko można zrobić statycznie...
<?php Class Static0 { { self::$counter = self::$counter + 2; } } Class Static1 extends Static0 { { self::$counter = self::$counter + 1; } { parent::incrByTwo(); } } for($i=0;$i<100000;$i++) { Static1::incrByOne(); Static1::incrByTwo(); } $time1 = $time_end - $time_start; ?>
<?php Class Static0 { public $counter = 0; public function incrByTwo() { $this->counter = $this->counter + 2; } } Class Static1 extends Static0 { public function incrByOne() { $this->counter = $this->counter + 1; } public function incrByTwo() { parent::incrByTwo(); } } $obj = new Static1(); for($i=0;$i<100000;$i++) { $obj->incrByOne(); $obj->incrByTwo(); } $time1 = $time_end - $time_start; ?>