Why is echo faster than printing?

In PHP , why is echofaster than print?

They do the same ... Why is one faster than the other?

Do they do exactly the same thing?

+3
source share
4 answers

echoand printin fact (not technically) the same thing. The difference between them (to a large extent) is that it printreturns an integer 1, while it echoreturns nothing. Keep in mind that none of them is a function, but rather builds a language. echoallows you to pass multiple lines when using it, as if it were a function (for example, echo($var1, $var2, $var3)).

echocan also be shortened with syntax <?= $var1; ?>(instead <?php echo $var1; ?>).

, -, . PHP Benchmark , " , . , , , .

, ( ) .

+6

1, , ,

+2

, .

The difference in speed (if any) is so minimal that it’s not worth the effort to think about micro-optimizations like this, and it’s completely not worth updating the old code to switch fingerprints to echo. There are much better ways to speed up your site if that is your goal.

+1
source

The differences are broken here: PHP performance: echo and print

0
source

Source: https://habr.com/ru/post/1761604/


All Articles