<?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; php5.3</title>
	<atom:link href="http://www.laruence.com/tag/php53/feed" rel="self" type="application/rss+xml" />
	<link>http://www.laruence.com</link>
	<description>PHP语言, PHP扩展, Zend引擎相关的研究,技术,新闻分享 - 左手代码 右手诗</description>
	<lastBuildDate>Wed, 08 Feb 2012 05:12:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>PHP5.3 α2初体验</title>
		<link>http://www.laruence.com/2008/09/20/523.html</link>
		<comments>http://www.laruence.com/2008/09/20/523.html#comments</comments>
		<pubDate>Fri, 19 Sep 2008 17:13:15 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[PHP应用]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php5.3]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=523</guid>
		<description><![CDATA[PHP5.3 α2 已经放出1个多月了, 最近一直都忙一些私人的事情, 今天终于有点时间.

赶紧下来试用,  apache2.x + php5.3 alpha2

changes:
 <ul>
	<li><a href="http://php.net/language.namespaces">Namespaces</a> (documentation maybe out dated)</li>
	<li><a href="http://php.net/oop5.late-static-bindings">Late static binding</a> and <a href="http://php.net/language.oop5.overloading">__callStatic</a></li>
	<li><a href="http://wiki.php.net/rfc/closures">Lambda functions and closures</a></li>
	<li>Addition of the <a href="http://php.net/book.intl">intl</a>, <a href="http://php.net/book.phar">phar</a> (phar is scheduled for some more work a head of alpha2), <a href="http://php.net/book.fileinfo">fileinfo </a>and <a href="http://php.net/book.sqlite3">sqlite3</a> extensions</li>
	<li>Optional cyclic garbage collection</li>
	<li>Optional support for the <a href="http://forge.mysql.com/wiki/PHP_MYSQLND">MySQLnd</a> replacement driver for libmysql</li>
	<li>Windows older than Windows 2000 (Windows 98, NT4, etc.) are not supported anymore (<a href="http://wiki.php.net/internals/windows/releasenotes">details</a>)</li>
	<li>New syntax features like <a href="http://php.net/language.types.string#language.types.string.syntax.nowdoc">NOWDOC</a>, limited GOTO, ternary short cut "?:"</li>
</ul>]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2008/09/20/523.html"  title="Permanet Link to PHP5.3 α2初体验" >http://www.laruence.com/2008/09/20/523.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>PHP5.3 α2 已经放出1个多月了, 最近一直都忙一些私人的事情, 今天终于有点时间.</p>
<p>赶紧下来试用,  apache2.x + php5.3 alpha2</p>
<p>在php src目录下,<br/>
./configure &#8211;with-apxs2=/usr/sbin/apxs<br/>
make<br/>
sudo make install<br/>
重启, apache无法启动,直接Segmentation fault. 研究了半天也没找到原因, 后来在conf目录下偶然的grep了一下,发现了原因,原来我这个环境以前是php4, 所以apache load了2次php module, <br/>
删除掉以后,重启apache, 一切正常&#8230;</p>
<p>赶紧来试试php5.3的新特性吧,在php.net上我们可以看到,php5.3的新特性有:</p>
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li><a href="http://php.net/language.namespaces" >Namespaces</a> (documentation maybe out dated)</li>
<li><a href="http://php.net/oop5.late-static-bindings" >Late static binding</a> and <a href="http://php.net/language.oop5.overloading" >__callStatic</a></li>
<li><a href="http://wiki.php.net/rfc/closures" >Lambda functions and closures</a></li>
<li>Addition of the <a href="http://php.net/book.intl" >intl</a>, <a href="http://php.net/book.phar" >phar</a> (phar is scheduled for some more work a head of alpha2), <a href="http://php.net/book.fileinfo" >fileinfo </a>and <a href="http://php.net/book.sqlite3" >sqlite3</a> extensions</li>
<li>Optional cyclic garbage collection</li>
<li>Optional support for the <a href="http://forge.mysql.com/wiki/PHP_MYSQLND" >MySQLnd</a> replacement driver for libmysql</li>
<li>Windows older than Windows 2000 (Windows 98, NT4, etc.) are not supported anymore (<a href="http://wiki.php.net/internals/windows/releasenotes" >details</a>)</li>
<li>New syntax features like <a href="http://php.net/language.types.string#language.types.string.syntax.nowdoc" >NOWDOC</a>, limited GOTO, ternary short cut &#8220;?:&#8221;</li>
</ul>
<p>等我好好研究研究, 回头写点试用手记. <img src="http://www.laruence.com/wp-includes/images/smilies/icon_wink.gif"  alt=";)"  class="wp-smiley" /><br/>
2008.09.22 about lambda function:</p>
<p>  PHP5.3开始支持Lambda风格的函数，如果大家对Js很熟悉的话， 对于这种风格的函数那就并不陌生了：<br/>
var func = function(para){<br/>
alert(para);<br/>
};<br/>
Lambda风格的函数，最初是(应该是，我猜测)由Lisp系语言中的匿名函数而来的, 在Scheme(Lisp系语言)中，定义一个匿名函数可以使用lambda关键字:</p>
<pre name="code"  class="sh_cpp"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
(define add1 (lambda(x)(+ x 1)));
</pre>
<p>在PHP中有很多可以使用回调函数的函数，比如array_map,array_walk, 我一直很郁闷的就是， 对于这样的函数，我必须要先定义个回叫函数，然后将回叫函数的字符串函数名作为参数传递，对于我这样的一个追求代码漂亮的人来说，我对这种方式简直可以说是深恶痛绝。<br/>
所以，在以前，我一直都是使用create_function来创建匿名函数， 可是用create_function的时候，函数体，参数都必须以字符串的方式传入，这样语法高亮就不能被应用，导致代码还是很ugly。</p>
<p>今天，我终于等到了PHP的Lamdba…</p>
<p>首先，让我们先用一个例子，来试试：</p>
<pre name="code"  class="sh_php"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt; ?php
$lambda_fuc = function($string){
print $string;
};
$lambda_fuc(&quot;laruence&quot;);
?&gt;
</pre>
<p>在PHP5.3的特性介绍中，也说明了，对于一个包含lambda函数的变量来说，可以有3种调用方式：</p>
<pre name="code"  class="sh_php"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
$lambda ();
call_user_func ($lambda);
call_user_func_array ($lambda, array ());
</pre>
<p>另外，对于匿名函数来说，最重要的伴随物就应该是闭包了(closure), PHP5.3中也同样支持了闭包，这样，我们就可以使用这个特性，来创建一些流程相同，但是数据并不完全的函数族，举个简单的例子：</p>
<pre name="code"  class="sh_php"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt; ?php
function closure($var){
return function($string) use ($var){
print $string . &quot;\n&quot; . $var;
};
}

$func = closure(&quot;laruence&quot;);
$func(&quot;I am&quot;);
?&gt;
</pre>
<p>当我们var_dump lambda函数的时候，会得到如下结果：</p>
<pre name="code"  class="sh_php"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
object(Closure)#1 (0) {
//process
}
</pre>
<p>在PHP5.3的特性介绍中，介绍了Lambda的实现具体机理：<br/>
在PHP的语法分析阶段，当遇到lambda函数申明的时候，会调用一个新加入的函数 zend_do_begin_lambda_function_declaration, 这个函数内部会以”lambda”作为参数来调用zend_do_begin_function_declaration，紧接着会以新加入的ZEND_DECLARE_LAMBDA_FUNCTION Opcode来替换生成的ZEND_DECLARE_FUNCTION，<br/>
在编译阶段，ZEND_DECLARE_LAMBDA_FUNCTION会创建一个Closure对象，然后将lambda函数的op_array保存，并使zend_call_fun和zend_is_callable_ex可以调用Closure对象。<script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_cpp.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_php.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_php.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_php.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_php.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/09/20/523.html" >2008/09/20</a>, snowrui writes: 5.3是有很多重大的改进和BUG修改.</li><li><a href="http://www.laruence.com/2008/09/20/523.html" >2008/09/20</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 恩,每个新的版本都会有对以前版本的bug的修改的作用的么,:)</li><li><a href="http://www.laruence.com/2008/09/20/523.html" >2008/09/20</a>, Anonymous writes: Lambda functions指的是什么呢？</li><li><a href="http://www.laruence.com/2008/09/20/523.html" >2008/09/20</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 简单来说lambda functions就是说函数体被赋值给一个变量的函数, 这个名字应该是源于Lisp/Scheme语言中的lambda(匿名函数):
(define func (lambda(p) (+ 1 p)));
在js中也很常见:
 var func = function(e){ return;};
恩, 插一句,想起来有人说过,js是一个披着C语言皮的Lisp.</li><li><a href="http://www.laruence.com/2008/09/20/523.html" >2009/05/10</a>, LungZeno writes: lambda 是指 lambda 演算（λ calculus）。
相比起 C 語言， Javascript 的很多語法都是刻意模仿 Java 的，例如
C 語言（不用 goto 的話）：
{
　DoSomeThing();
　if(SomeConditions)
　　break;
　DoAnotherSomeThing();
} while(0);

Javascript 和 Java：
workA: {
　doSomeThing();
　if(someConditions)
　　break workA;
　doAnotherSomeThing();
}</li><li><a href="http://www.laruence.com/2008/09/20/523.html" >2009/05/10</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 你的知识面也是很广啊？ 呵呵
留个MSN或者其他的联系方式吧？ 以后多多请教。。</li><li><a href="http://www.laruence.com/2008/09/20/523.html" >2009/07/16</a>, <a href="http://www.find888.cn"  rel="external nofollow"  class="url" >公司简介</a> writes: 好好休息</li><li><a href="http://www.laruence.com/2008/09/20/523.html" >2009/10/26</a>, <a href="http://www.pigblog.net"  rel="external nofollow"  class="url" >Cherry</a> writes: 对于PHP5.3的特性一直后知后觉，之前装了5.3可是公司大部分程序就废了，导致没有机会来研究下5.3，不知道为什么我会搜索PHP5.3 然后不知道为什么就来到这里，发现了高人，以后常来，订阅你的博客啦。</li><li><a href="http://www.laruence.com/2008/09/20/523.html" >2010/07/29</a>, laura writes: through some major changes many aficionados <a href="http://www.watchesfaner.com/breitling-watches.html"  rel="nofollow" >fake breitling watches for sale</a> yachtmaster ii watches is definitely a unique royal choice which is <a href="http://www.watchesfaner.com/a_lange_and_sohne-watches.html"  rel="nofollow" >a lange and sohne watches</a> cpcp watches this homecoming the return to our roots at The <a href="http://www.sanwatches.com/omega-watches.html"  rel="nofollow" >omega replica watches</a> fake jaeger lecoultre bracelet watches many of which go rather well with <a href="http://www.watchesfaner.com/rolex-watches.html"  rel="nofollow" >rolex replica</a> datejust watches more practical The i:VIRT M Edition from Citizen <a href="http://www.sanwatches.com/"  rel="nofollow" >replica watches</a> italian sports car: they werent designed with the <a href="http://www.sanwatches.com/audemars_piguet-jules_audemars-watches.html"  rel="nofollow" >replica audemars piguet jules audemars watches</a> Shopping Bag: 0 Items Funky Colourful Watches  The <a href="http://www.watchesfaner.com/gucci-watches.html"  rel="nofollow" >replica gucci watches</a> Cartier watch then some people are likely to pay <a href="http://www.sanwatches.com/"  rel="nofollow" >fake watch</a> adding a certain level of vibrancy to an outfit in <a href="http://www.watchesfaner.com/"  rel="nofollow" >replica watch</a> are available at very moderate prices Herbert <a href="http://www.sanwatches.com/"  rel="nofollow" >watches replica</a> indeed like no other watch on earth  Ikepod <a href="http://www.pocwatches.com/cartier-watches.html"  rel="nofollow" >cartier watches replica</a> tluminor marina watches the showcase to allow a wide range of choice The <a href="http://www.corwatches.org/mens_watches.html"  rel="nofollow" >mens watches</a> skeletonized lug design showcases its fine tooling</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/10/12/1763.html"  title="PHP的命名空间的实现" >PHP的命名空间的实现</a></li><li><a href="http://www.laruence.com/2012/02/08/2528.html"  title="PHP-5.3.9远程执行任意代码漏洞(CVE-2012-0830)" >PHP-5.3.9远程执行任意代码漏洞(CVE-2012-0830)</a></li><li><a href="http://www.laruence.com/2012/02/02/2515.html"  title="我们什么时候应该使用异常?" >我们什么时候应该使用异常?</a></li><li><a href="http://www.laruence.com/2012/02/01/2503.html"  title="使用exit(-1)为什么得到255退出码?" >使用exit(-1)为什么得到255退出码?</a></li><li><a href="http://www.laruence.com/2012/01/11/2482.html"  title="PHP的历史" >PHP的历史</a></li><li><a href="http://www.laruence.com/2012/01/10/2469.html"  title="如何设置一个严格30分钟过期的Session" >如何设置一个严格30分钟过期的Session</a></li><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2011/12/30/2440.html"  title="PHP5.2.*防止Hash冲突拒绝服务攻击的Patch" >PHP5.2.*防止Hash冲突拒绝服务攻击的Patch</a></li><li><a href="http://www.laruence.com/2011/12/30/2435.html"  title="PHP数组的Hash冲突实例" >PHP数组的Hash冲突实例</a></li><li><a href="http://www.laruence.com/2011/12/29/2412.html"  title="通过构造Hash冲突实现各种语言的拒绝服务攻击" >通过构造Hash冲突实现各种语言的拒绝服务攻击</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2008/09/20/523.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

