简单的回答,显然是苍白无力的。 今天我们来做个实验,看看到底单引号和双引号有什么区别,谁快,谁慢。
测试代码如下:
复制代码 代码如下:
$single_quotes = 'This is a String';
$double_quotes = "This is a String";
echo $single_quotes;
echo $double_quotes;
$var = 'String';
$single_quotes_var = 'This is a '.$var;
$double_quotes_var = "This is a $var";
echo $single_quotes_var;
echo $double_quotes_var;
$var = 'This';
$single_quotes_var_pre = $var . ' is a String';
$double_quotes_var_pre = "$var is a String";
echo $single_quotes_var_pre;
echo $double_quotes_var_pre;
?>
复制代码 代码如下:
Branch analysis from position: 0
Return found
filename: /home/xinchen/string.php
function name: (null)
number of ops: 24
compiled vars: !0 = $single_quotes, !1 = $double_quotes, !2 = $var, !3 = $single_quotes_var, !4 = $double_quotes_var, !5 = $single_quotes_var_pre, !6 = $double_quotes_var_pre
line # op fetch ext return operands
-------------------------------------------------------------------------------
2 0 ASSIGN !0, 'This+is+a+String'
3 1 ASSIGN !1, 'This+is+a+String'
4 2 ECHO !0
5 3 ECHO !1
7 4 ASSIGN !2, 'String'
8 5 CONCAT ~3 'This+is+a+', !2
6 ASSIGN !3, ~3
9 7 INIT_STRING ~5
8 ADD_STRING ~5 ~5, 'This+is+a+'
9 ADD_VAR ~5 ~5, !2
10 ASSIGN !4, ~5
11 11 ECHO !3
12 12 ECHO !4
14 13 ASSIGN !2, 'This'
16 14 CONCAT ~8 !2, '+is+a+String'
15 ASSIGN !5, ~8
17 16 INIT_STRING ~10
17 ADD_VAR ~10 ~10, !2
18 ADD_STRING ~10 ~10, '+is+a+String'
19 ASSIGN !6, ~10
19 20 ECHO !5
20 21 ECHO !6
22 22 RETURN 1
23* ZEND_HANDLE_EXCEPTION