<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>潘锦的空间 &#187; 字符串内用使用变量</title>
	<atom:link href="https://www.phppan.com/tag/%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%86%85%e7%94%a8%e4%bd%bf%e7%94%a8%e5%8f%98%e9%87%8f/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.phppan.com</link>
	<description>SaaS SaaS架构 团队管理 技术管理 技术架构 PHP 内核 扩展 项目管理</description>
	<lastBuildDate>Sat, 04 Apr 2026 01:19:58 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>点号连接符与字符串内用使用变量的速度比较</title>
		<link>https://www.phppan.com/2009/09/dot-connector-variable-speed/</link>
		<comments>https://www.phppan.com/2009/09/dot-connector-variable-speed/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 06:07:07 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[使用VLD]]></category>
		<category><![CDATA[字符串内用使用变量]]></category>
		<category><![CDATA[点号连接符]]></category>

		<guid isPermaLink="false">http://www.phppan.com/?p=196</guid>
		<description><![CDATA[一直喜欢在字符串内使用大括号包含变量，但是看到别人的程序中经常用点号连接。 难道这样快些？ 于是对下面三种情况 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>一直喜欢在字符串内使用大括号包含变量，但是看到别人的程序中经常用点号连接。<br />
难道这样快些？<br />
于是对下面三种情况进行了测试：<br />
1、	使用点号连接字符串和字符串变量。<br />
2、	在字符串中使用大括号包含变量；<br />
3、	在字符串中不使用大括号包含变量；</p>
<p>1、使用点号连接字符串和字符串变量</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?PHP</span>
	<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;abcd&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$str2</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$str</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;efg&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>使用VLD查看结果如下：<br />
Branch analysis from position: 12647312<br />
Return found<br />
filename:       D:\work\php\test.php<br />
function name:  (null)<br />
number of ops:  8<br />
compiled vars:  !0 = $str, !1 = $str2<br />
line     #  op                           fetch          ext  return  operands<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
   2     0  EXT_STMT<br />
         1  ASSIGN                                                   !0, &#8216;abcd&#8217;<br />
   3     2  EXT_STMT<br />
         3  CONCAT                                           ~1      !0, &#8216;efg&#8217;<br />
         4  ASSIGN                                                   !1, ~1<br />
   4     5  EXT_STMT<br />
         6  RETURN                                                   1<br />
         7* ZEND_HANDLE_EXCEPTION</p>
<p>2、在字符串中使用大括号：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?PHP</span>
	<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;abcd&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$str2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$st}</span>refg&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Branch analysis from position: 12647312<br />
Return found<br />
filename:       D:\work\php\test.php<br />
function name:  (null)<br />
number of ops:  10<br />
compiled vars:  !0 = $str, !1 = $str2<br />
line     #  op                           fetch          ext  return  operands<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
   2     0  EXT_STMT<br />
         1  ASSIGN                                                   !0, &#8216;abcd&#8217;<br />
   3     2  EXT_STMT<br />
         3  INIT_STRING                                      ~1<br />
         4  ADD_VAR                                          ~1      ~1, !0<br />
         5  ADD_STRING                                       ~1      ~1, &#8216;efg&#8217;<br />
         6  ASSIGN                                                   !1, ~1<br />
   4     7  EXT_STMT<br />
         8  RETURN                                                   1<br />
         9* ZEND_HANDLE_EXCEPTION</p>
<p>3、在字符串中不使用大括号包含变量</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?PHP</span>
	<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;abcd&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$str2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$strefg</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Branch analysis from position: 12647312<br />
Return found<br />
filename:       D:\work\php\test.php<br />
function name:  (null)<br />
number of ops:  9<br />
compiled vars:  !0 = $str, !1 = $str2, !2 = $strefg<br />
line     #  op                           fetch          ext  return  operands<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
   2     0  EXT_STMT<br />
         1  ASSIGN                                                   !0, &#8216;abcd&#8217;<br />
   3     2  EXT_STMT<br />
         3  INIT_STRING                                      ~1<br />
         4  ADD_VAR                                          ~1      ~1, !2<br />
         5  ASSIGN                                                   !1, ~1<br />
   4     6  EXT_STMT<br />
         7  RETURN                                                   1<br />
         8* ZEND_HANDLE_EXCEPTION</p>
<p>另外，对于这样的两条语句执行一百万次，其结果如下：<br />
1、使用点号连接字符串和字符串变量：平均在0.6秒<br />
2、在字符串中使用大括号包含变量：平均在1.75左右<br />
3、在字符串中不使用大括号包含变量: 平均在1.7秒左右<br />
明显第一种要一些，从VLD查看的结果中可以看出后面两种与第一种的实现方式完全不同，后面两种多了INIT_STRING和ADD_VAR的操作。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.phppan.com/2009/09/dot-connector-variable-speed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
