ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 第十五课 php5.3+新特性 **const 关键字可用来在类外定义常量 5.3** const HI="定义常量另一种方法"; **nowdoc传递一段代码不解析变量,类似heredoc5.3** ``` <pre class="calibre14">``` $str <span class="token">=</span> <span class="token"><</span><span class="token"><</span><span class="token"><</span><span class="token4">'EOD'</span> 这里可以是代码$qq不解析 EOD<span class="token2">;</span> echo $str<span class="token2">;</span> ``` ``` **命名空间5.3** ``` <pre class="calibre14">``` namespace A<span class="token2">;</span> class <span class="token1">B</span><span class="token2">{</span> <span class="token2">}</span> $c <span class="token">=</span> <span class="token5">new</span> <span class="token1"><span class="token2">\</span>A<span class="token2">\</span>B</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> ``` ``` **短数组5.4** ``` <pre class="calibre14">``` $arr <span class="token">=</span> <span class="token2">[</span><span class="token4">"key"</span> <span class="token">=</span><span class="token">></span> <span class="token4">"value"</span><span class="token2">,</span> <span class="token4">"key2"</span> <span class="token">=</span><span class="token">></span> <span class="token4">"value2"</span><span class="token2">]</span><span class="token2">;</span> $arr <span class="token">=</span> <span class="token2">[</span><span class="token3">1</span><span class="token2">,</span><span class="token3">2</span><span class="token2">,</span><span class="token3">3</span><span class="token2">,</span><span class="token3">4</span><span class="token2">]</span><span class="token2">;</span> ``` ``` **函数返回数组5.4** myfunc()\[0\]; **实例化访问类成员5.4** (new Foo)->bar(); **json不转换中文5.4** json\_encode(array("中文"), JSON\_UNESCAPED\_UNICODE); **函数中传递引用** ``` <pre class="calibre14">``` <span class="token5">function</span> <span class="token1">goo</span><span class="token2">(</span><span class="token">&</span>$a<span class="token2">)</span> <span class="token2">{</span> <span class="token5">return</span> $a <span class="token">=</span> <span class="token3">100</span><span class="token2">;</span> <span class="token2">}</span> $a <span class="token">=</span> <span class="token3">3</span><span class="token2">;</span> echo <span class="token1">goo</span><span class="token2">(</span>$a<span class="token2">)</span><span class="token2">;</span><span class="token6">//输出100</span> ``` ``` always\_populate\_raw\_post\_data = -1 5.6报错