【发布时间】:2012-05-23 14:59:09
【问题描述】:
可能重复:
Is there a performance benefit single quote vs double quote in php?
我想知道在定义字符串不包含变量时使用"s 时PHP 代码是否会降低性能,而' 不执行额外的解析。
例如,PHP 会尝试解析由" 定义的字符串中的变量,而不是'。
$myString = "Greetings earthlings!";
echo '$myString'; //literally outputs the string '$myString'
echo "$myString"; //literally outputs the string "Greetings earthlings"
所以我的问题是,我一直在编写这样的代码:
echo "Greetings earthlings";
我是否一直在浪费周期?或者 PHP 是否足够聪明/优化到足以知道我 真的 的意思:
echo 'Greetings earthlings';
?
【问题讨论】:
-
是的,但它是如此之小,它并不是真正的考虑因素。在网络上某处有一个差异基准。但您可以在不到一分钟的时间内完成您自己的操作。 phpbench.com
标签: php optimization php-opcode