Quickly understand the new features of each version of PHP7.X
Jul 27, 2022 pm 02:54 PMThis article will take you through the new features of each version of PHP7.
As we all know, PHP is constantly being updated and expanded, and each version has a performance improvement. Next, I will explain to you the features of PHP7. New features. I will explain each version according to its features.
- New features of PHP7.0
- New features of PHP7.1
- New features of PHP7.2 Features
- New features of PHP7.3
- New features of PHP7.4
PHP7.0 new features
1. Declaration of scalar type
There are two modes for scalar type declaration: mandatory (default) and strict mode. The following type parameters can now be used (either in forced or strict mode): String (<span class="type">string</span>), Integer (<em>int</em>), Float (<span class="type">float</span>) , and Boolean values ??(<em>bool</em>). They extend other types introduced in PHP5: class names, interfaces, arrays and callback types.
PHP scalars include: string (<span class="type">string</span>
), integer (<em>int</em>
), floating point number (<span class="type">float</span>
), and Boolean value (<em>bool</em>
).
For example, below we define a parameter whose formal parameter is an integer. (The correct one is as follows)
<?php //Enter your code here, enjoy! function sumOfInts(int ...$ints) { return array_sum($ints); } var_dump(sumOfInts(2, '3', 4.1));
Output:
int(9)
For example, below we define a parameter whose formal parameter is an integer. (The error is as follows)
<?php //Enter your code here, enjoy! function sumOfInts(int ...$ints) { return array_sum($ints); } var_dump(sumOfInts(2, 'error', 4.1));//參數(shù)里面有字符串,我們聲明的是整數(shù)
Output error message:
<br /> <b>Fatal error</b>: Uncaught TypeError: Argument 2 passed to sumOfInts() must be of the type integer, string given, called in [...][...] on line 8 and defined in [...][...]:3 Stack trace: #0 [...][...](8): sumOfInts(2, 'error', 4.1) #1 {main} thrown in <b>[...][...]</b> on line <b>3</b><br />
2. Return value type declaration
PHP 7 adds the return type declaration support. Similar to the parameter type declaration, the return type declaration specifies the type of the function's return value. The available types are the same as those available in the parameter declaration.
For example, below we define a function whose return value is an array.
<?php function arraysSum(array ...$arrays): array { return array_map(function(array $array): int { return array_sum($array); }, $arrays); } print_r(arraysSum([1,2,3], [4,5,6], [7,8,9]));
Output:
Array ( [0] => 6 [1] => 15 [2] => 24 )
3.null coalescing operator
Due to the large number of simultaneous uses of ternary expressions and isset() in daily use In this case, we added the syntactic sugar of null coalescing operator (??). If the variable exists and is not NULL, it returns its own value, otherwise it returns its second operand.
<?php // 如果$_GET['user']不存在就執(zhí)行nobody賦值給$username $username = $_GET['user'] ?? 'nobody'; // 上面的語(yǔ)句相當(dāng)于下面的語(yǔ)句 $username = isset($_GET['user']) ? $_GET['user'] : 'nobody'; // Coalesces can be chained: this will return the first // defined value out of $_GET['user'], $_POST['user'], and // 'nobody'. $username = $_GET['user'] ?? $_POST['user'] ?? 'nobody'; ?>
4. Spaceship operator (combined comparison operator)
The spaceship operator is used to compare two expressions. It returns -1, 0 or 1 when $a is less than, equal to or greater than $b respectively. The principle of comparison follows PHP's regular comparison rules.
<?php // 整數(shù) echo 1 <=> 1; // 0 echo 1 <=> 2; // -1 echo 2 <=> 1; // 1 // 浮點(diǎn)數(shù) echo 1.5 <=> 1.5; // 0 echo 1.5 <=> 2.5; // -1 echo 2.5 <=> 1.5; // 1 // 字符串 echo "a" <=> "a"; // 0 echo "a" <=> "b"; // -1 echo "b" <=> "a"; // 1 ?>
5. Define constant arrays through define()
Constants of Array type can now be defined through define(). In PHP5.6 it can only be defined via const.
<?php define('ANIMALS', [ 'dog', 'cat', 'bird' ]); echo ANIMALS[1]; // 輸出 "cat" ?>
6. Anonymous class
now supports instantiating an anonymous class through new class, which can be used to replace some "after-use Complete class definition for "Instant Burn".
<?php interface Logger { public function log(string $msg); } class Application { private $logger; public function getLogger(): Logger { return $this->logger; } public function setLogger(Logger $logger) { $this->logger = $logger; } } $app = new Application; $app->setLogger(new class implements Logger { public function log(string $msg) { echo $msg; } }); var_dump($app->getLogger()); ?>
The above routine will output:
object(class@anonymous)#2 (0) { }
7.Unicode codepoint translation syntax
This accepts a Unicode codepoint in hexadecimal form, And print out a UTF-8 encoded string surrounded by double quotes or heredoc. Any valid codepoint is accepted, and the leading 0 can be omitted.
echo "\u{aa}"; echo "\u{0000aa}"; echo "\u{9999}";
The above routine will output:
a a (same as before but with optional leading 0's) 香
8.Closure::call()
Closure::call () now has better performance and is a short and concise way to temporarily bind a method to a closure on an object and call it.
<?php class A {private $x = 1;} // PHP 7 之前版本的代碼 $getXCB = function() {return $this->x;}; $getX = $getXCB->bindTo(new A, 'A'); // 中間層閉包 echo $getX(); // PHP 7+ 及更高版本的代碼 $getX = function() {return $this->x;}; echo $getX->call(new A);
The above routine will output:
1 1
9.unserialize() provides filtering
This feature is designed to provide a safer way to unpack Unreliable data. It prevents potential code injection through whitelisting.
// 將所有的對(duì)象都轉(zhuǎn)換為 __PHP_Incomplete_Class 對(duì)象 $data = unserialize($foo, ["allowed_classes" => false]); // 將除 MyClass 和 MyClass2 之外的所有對(duì)象都轉(zhuǎn)換為 __PHP_Incomplete_Class 對(duì)象 $data = unserialize($foo, ["allowed_classes" => ["MyClass", "MyClass2"]); // 默認(rèn)情況下所有的類(lèi)都是可接受的,等同于省略第二個(gè)參數(shù) $data = unserialize($foo, ["allowed_classes" => true]);
10.IntlChar
The newly added IntlChar class is designed to expose more ICU functions. This class itself defines many static methods for operating unicode characters from multiple character sets.
<?php printf('%x', IntlChar::CODEPOINT_MAX); echo IntlChar::charName('@'); var_dump(IntlChar::ispunct('!'));
The above routine will output:
10ffff COMMERCIAL AT bool(true)
若要使用此類(lèi),請(qǐng)先安裝Intl擴(kuò)展
11.預(yù)期
預(yù)期是向后兼用并增強(qiáng)之前的 assert() 的方法。 它使得在生產(chǎn)環(huán)境中啟用斷言為零成本,并且提供當(dāng)斷言失敗時(shí)拋出特定異常的能力。
老版本的API出于兼容目的將繼續(xù)被維護(hù),assert()現(xiàn)在是一個(gè)語(yǔ)言結(jié)構(gòu),它允許第一個(gè)參數(shù)是一個(gè)表達(dá)式,而不僅僅是一個(gè)待計(jì)算的 string或一個(gè)待測(cè)試的boolean。
<?php ini_set('assert.exception', 1); class CustomError extends AssertionError {} assert(false, new CustomError('Some error message')); ?>
以上例程會(huì)輸出:
Fatal error: Uncaught CustomError: Some error message
關(guān)于這個(gè)特性的完整說(shuō)明,包括如何在開(kāi)發(fā)和生產(chǎn)環(huán)境中配置它,可以在assert()的 expectations section章節(jié)找到。
12.Group use declarations
從同一 namespace 導(dǎo)入的類(lèi)、函數(shù)和常量現(xiàn)在可以通過(guò)單個(gè) use 語(yǔ)句 一次性導(dǎo)入了。
<?php // PHP 7 之前的代碼 use some\namespace\ClassA; use some\namespace\ClassB; use some\namespace\ClassC as C; use function some\namespace\fn_a; use function some\namespace\fn_b; use function some\namespace\fn_c; use const some\namespace\ConstA; use const some\namespace\ConstB; use const some\namespace\ConstC; // PHP 7+ 及更高版本的代碼 use some\namespace\{ClassA, ClassB, ClassC as C}; use function some\namespace\{fn_a, fn_b, fn_c}; use const some\namespace\{ConstA, ConstB, ConstC}; ?>
13.生成器可以返回表達(dá)式
此特性基于 PHP 5.5 版本中引入的生成器特性構(gòu)建的。 它允許在生成器函數(shù)中通過(guò)使用 return 語(yǔ)法來(lái)返回一個(gè)表達(dá)式 (但是不允許返回引用值), 可以通過(guò)調(diào)用 Generator::getReturn() 方法來(lái)獲取生成器的返回值, 但是這個(gè)方法只能在生成器完成產(chǎn)生工作以后調(diào)用一次。
<?php $gen = (function() { yield 1; yield 2; return 3; })(); foreach ($gen as $val) { echo $val, PHP_EOL; } echo $gen->getReturn(), PHP_EOL;
以上例程會(huì)輸出:
1 2 3
在生成器中能夠返回最終的值是一個(gè)非常便利的特性, 因?yàn)樗沟谜{(diào)用生成器的客戶端代碼可以直接得到生成器(或者其他協(xié)同計(jì)算)的返回值, 相對(duì)于之前版本中客戶端代碼必須先檢查生成器是否產(chǎn)生了最終的值然后再進(jìn)行響應(yīng)處理 來(lái)得方便多了。
14.Generator delegation
現(xiàn)在,只需在最外層生成其中使用 yield from, 就可以把一個(gè)生成器自動(dòng)委派給其他的生成器, Traversable 對(duì)象或者 array。
<?php function gen() { yield 1; yield 2; yield from gen2(); } function gen2() { yield 3; yield 4; } foreach (gen() as $val) { echo $val, PHP_EOL; } ?>
以上例程會(huì)輸出:
1 2 3 4
15.整數(shù)除法函數(shù) intdiv()
新加的函數(shù) intdiv() 用來(lái)進(jìn)行 整數(shù)的除法運(yùn)算。
<?php var_dump(intdiv(10, 3)); ?>
以上例程會(huì)輸出:
int(3)
16.會(huì)話選項(xiàng)
session_start() 可以接受一個(gè) array 作為參數(shù), 用來(lái)覆蓋 php.ini 文件中設(shè)置的 會(huì)話配置選項(xiàng)。
在調(diào)用 session_start() 的時(shí)候, 傳入的選項(xiàng)參數(shù)中也支持 session.lazy_write 行為, 默認(rèn)情況下這個(gè)配置項(xiàng)是打開(kāi)的。它的作用是控制 PHP 只有在會(huì)話中的數(shù)據(jù)發(fā)生變化的時(shí)候才 寫(xiě)入會(huì)話存儲(chǔ)文件,如果會(huì)話中的數(shù)據(jù)沒(méi)有發(fā)生改變,那么 PHP 會(huì)在讀取完會(huì)話數(shù)據(jù)之后, 立即關(guān)閉會(huì)話存儲(chǔ)文件,不做任何修改,可以通過(guò)設(shè)置 read_and_close 來(lái)實(shí)現(xiàn)。
例如,下列代碼設(shè)置 session.cache_limiter 為 private,并且在讀取完畢會(huì)話數(shù)據(jù)之后馬上關(guān)閉會(huì)話存儲(chǔ)文件。
<?php session_start([ 'cache_limiter' => 'private', 'read_and_close' => true, ]); ?>
17.preg_replace_callback_array()
在 PHP 7 之前,當(dāng)使用 preg_replace_callback() 函數(shù)的時(shí)候, 由于針對(duì)每個(gè)正則表達(dá)式都要執(zhí)行回調(diào)函數(shù),可能導(dǎo)致過(guò)多的分支代碼。 而使用新加的 preg_replace_callback_array() 函數(shù), 可以使得代碼更加簡(jiǎn)潔。
現(xiàn)在,可以使用一個(gè)關(guān)聯(lián)數(shù)組來(lái)對(duì)每個(gè)正則表達(dá)式注冊(cè)回調(diào)函數(shù), 正則表達(dá)式本身作為關(guān)聯(lián)數(shù)組的鍵, 而對(duì)應(yīng)的回調(diào)函數(shù)就是關(guān)聯(lián)數(shù)組的值。
18.CSPRNG Functions
新加入兩個(gè)跨平臺(tái)的函數(shù): random_bytes() 和 random_int() 用來(lái)產(chǎn)生高安全級(jí)別的隨機(jī)字符串和隨機(jī)整數(shù)。
可以使用 list() 函數(shù)來(lái)展開(kāi)實(shí)現(xiàn)了 ArrayAccess 接口的對(duì)象 ?
在之前版本中,list() 函數(shù)不能保證 正確的展開(kāi)實(shí)現(xiàn)了 ArrayAccess 接口的對(duì)象, 現(xiàn)在這個(gè)問(wèn)題已經(jīng)被修復(fù)。
19.其他特性
允許在克隆表達(dá)式上訪問(wèn)對(duì)象成員,例如: (clone $foo)->bar()。
PHP7.1新特性
1.可為空(Nullable)類(lèi)型
參數(shù)以及返回值的類(lèi)型現(xiàn)在可以通過(guò)在類(lèi)型前加上一個(gè)問(wèn)號(hào)使之允許為空。 當(dāng)啟用這個(gè)特性時(shí),傳入的參數(shù)或者函數(shù)返回的結(jié)果要么是給定的類(lèi)型,要么是 null 。
<?php function testReturn(): ?string { return 'elePHPant'; } var_dump(testReturn()); function testReturn(): ?string { return null; } var_dump(testReturn()); function test(?string $name) { var_dump($name); } test('elePHPant'); test(null); test();
以上例程會(huì)輸出:
string(10) "elePHPant" NULL string(10) "elePHPant" NULL Uncaught Error: Too few arguments to function test(), 0 passed in...
2.Void 函數(shù)
一個(gè)新的返回值類(lèi)型void被引入。 返回值聲明為 void 類(lèi)型的方法要么干脆省去 return 語(yǔ)句,要么使用一個(gè)空的 return 語(yǔ)句。 對(duì)于 void 函數(shù)來(lái)說(shuō),NULL
不是一個(gè)合法的返回值。
<?php function swap(&$left, &$right) : void { if ($left === $right) { return; } $tmp = $left; $left = $right; $right = $tmp; } $a = 1; $b = 2; var_dump(swap($a, $b), $a, $b);
以上例程會(huì)輸出:
null int(2) int(1)
試圖去獲取一個(gè) void 方法的返回值會(huì)得到 NULL ,并且不會(huì)產(chǎn)生任何警告。這么做的原因是不想影響更高層次的方法。
3.類(lèi)常量可見(jiàn)性
<?php class Sky8g { const PUBLIC_CONST_A = 1; public const PUBLIC_CONST_B = 2; protected const PROTECTED_CONST = 3; private const PRIVATE_CONST = 4; }
4.iterable偽類(lèi)
現(xiàn)在引入了一個(gè)新的被稱(chēng)為iterable的偽類(lèi) (與callable類(lèi)似)。 這可以被用在參數(shù)或者返回值類(lèi)型中,它代表接受數(shù)組或者實(shí)現(xiàn)了Traversable接口的對(duì)象。 至于子類(lèi),當(dāng)用作參數(shù)時(shí),子類(lèi)可以收緊父類(lèi)的iterable類(lèi)型到array 或一個(gè)實(shí)現(xiàn)了Traversable的對(duì)象。對(duì)于返回值,子類(lèi)可以拓寬父類(lèi)的 array或?qū)ο蠓祷刂殿?lèi)型到iterable。
<?php function iterator(iterable $iter) { foreach ($iter as $val) { // } }
5.多異常捕獲處理
一個(gè)catch語(yǔ)句塊現(xiàn)在可以通過(guò)管道字符(|)來(lái)實(shí)現(xiàn)多個(gè)異常的捕獲。 這對(duì)于需要同時(shí)處理來(lái)自不同類(lèi)的不同異常時(shí)很有用。
<?php try { // some code } catch (FirstException | SecondException $e) { // handle first and second exceptions }
6.list()現(xiàn)在支持鍵名
現(xiàn)在list()和它的新的[]語(yǔ)法支持在它內(nèi)部去指定鍵名。這意味著它可以將任意類(lèi)型的數(shù)組 都賦值給一些變量(與短數(shù)組語(yǔ)法類(lèi)似)
<?php $data = [ ["id" => 1, "name" => 'Tom'], ["id" => 2, "name" => 'Fred'], ]; // list() style list("id" => $id1, "name" => $name1) = $data[0]; // [] style ["id" => $id1, "name" => $name1] = $data[0]; // list() style foreach ($data as list("id" => $id, "name" => $name)) { // logic here with $id and $name } // [] style foreach ($data as ["id" => $id, "name" => $name]) { // logic here with $id and $name }
7.支持為負(fù)的字符串偏移量
現(xiàn)在所有支持偏移量的字符串操作函數(shù) 都支持接受負(fù)數(shù)作為偏移量,包括通過(guò)[]或{}操作字符串下標(biāo)。在這種情況下,一個(gè)負(fù)數(shù)的偏移量會(huì)被理解為一個(gè)從字符串結(jié)尾開(kāi)始的偏移量。
<?php var_dump("abcdef"[-2]); var_dump(strpos("aabbcc", "b", -3));
以上例程會(huì)輸出:
string (1) "e" int(3)
PHP7.2新特性
1.新的對(duì)象類(lèi)型
這種新的對(duì)象類(lèi)型<span class="type">object</span>
, 引進(jìn)了可用于逆變(contravariant)參數(shù)輸入和協(xié)變(covariant)返回任何對(duì)象類(lèi)型。
<?php function test(object $obj) : object { return new SplQueue(); } test(new StdClass());
2.通過(guò)名稱(chēng)加載擴(kuò)展
擴(kuò)展文件不再需要通過(guò)文件加載 (Unix下以<em>.so</em>
為文件擴(kuò)展名,在Windows下以
<em>.dll</em>
為文件擴(kuò)展名) 進(jìn)行指定。可以在php.ini
配置文件進(jìn)行啟用, 也可以使用 <span class="function">dl()</span>
函數(shù)進(jìn)行啟用。
3.允許重寫(xiě)抽象方法(Abstract method)
當(dāng)一個(gè)抽象類(lèi)繼承于另外一個(gè)抽象類(lèi)的時(shí)候,繼承后的抽象類(lèi)可以重寫(xiě)被繼承的抽象類(lèi)的抽象方法。
<?php abstract class A { abstract function test(string $s); } abstract class B extends A { // overridden - still maintaining contravariance for parameters and covariance for return abstract function test($s) : int; }
4.使用Argon2算法生成密碼散列
Argon2 已經(jīng)被加入到密碼散列(password hashing) API (這些函數(shù)以 password_ 開(kāi)頭), 以下是暴露出來(lái)的常量:
PASSWORD_ARGON2I
PASSWORD_ARGON2_DEFAULT_MEMORY_COST
PASSWORD_ARGON2_DEFAULT_TIME_COST
PASSWORD_ARGON2_DEFAULT_THREADS
5.新增 ext/PDO(PDO擴(kuò)展) 字符串?dāng)U展類(lèi)型
當(dāng)你準(zhǔn)備支持多語(yǔ)言字符集,PDO的字符串類(lèi)型已經(jīng)擴(kuò)展支持國(guó)際化的字符集。以下是擴(kuò)展的常量:
PDO::PARAM_STR_NATL
PDO::PARAM_STR_CHAR
PDO::ATTR_DEFAULT_STR_PARAM
這些常量通過(guò)PDO::PARAM_STR
利用位運(yùn)算OR進(jìn)行計(jì)算:
<?php $db->quote('über', PDO::PARAM_STR | PDO::PARAM_STR_NATL);
6.為 ext/PDO新增額外的模擬調(diào)試信息
<span class="function">PDOStatement::debugDumpParams()</span>
方法已經(jīng)更新,當(dāng)發(fā)送SQL到數(shù)據(jù)庫(kù)的時(shí)候,在一致性、行查詢(包括替換綁定占位符)將會(huì)顯示調(diào)試信息。這一特性已經(jīng)加入到模擬調(diào)試中(在模擬調(diào)試打開(kāi)時(shí)可用)。
7.ext/LDAP(LDAP擴(kuò)展) 支持新的操作方式
LDAP 擴(kuò)展已經(jīng)新增了EXOP支持. 擴(kuò)展暴露以下函數(shù)和常量:
<span class="simpara"><span class="function">ldap_parse_exop()</span></span>
<span class="simpara"><span class="function">ldap_exop()</span></span>
<span class="simpara"><span class="function">ldap_exop_passwd()</span></span>
<span class="simpara"><span class="function">ldap_exop_whoami()</span></span>
LDAP_EXOP_START_TLS
LDAP_EXOP_MODIFY_PASSWD
LDAP_EXOP_REFRESH
LDAP_EXOP_WHO_AM_I
LDAP_EXOP_TURN
8.ext/sockets(sockets擴(kuò)展)添加了地址信息
sockets擴(kuò)展現(xiàn)在具有查找地址信息的能力,且可以連接到這個(gè)地址,或者進(jìn)行綁定和解析。為此添加了以下一些函數(shù):
- socket_addrinfo_lookup()
- socket_addrinfo_connect()
- socket_addrinfo_bind()
- socket_addrinfo_explain()
9.擴(kuò)展了參數(shù)類(lèi)型
重寫(xiě)方法和接口實(shí)現(xiàn)的參數(shù)類(lèi)型現(xiàn)在可以省略了。不過(guò)這仍然是符合LSP,因?yàn)楝F(xiàn)在這種參數(shù)類(lèi)型是逆變的。
<?php interface A { public function Test(array $input); } class B implements A { public function Test($input){} // type omitted for $input }
10.允許分組命名空間的尾部逗號(hào)
命名空間可以在PHP 7中使用尾隨逗號(hào)進(jìn)行分組引入。
<?php use Foo\Bar\{ Foo, Bar, Baz, };
PHP7.3新特性
1.Unicode 11支持
多字節(jié)字符串?dāng)?shù)據(jù)表已更新為Unicode 11。
2.長(zhǎng)字符串的支持
多字節(jié)字符串函數(shù)現(xiàn)在正確支持大于2GB的字符串。
3.性能改進(jìn)
多字節(jié)字符串?dāng)U展的性能得到了全面的顯著改善。最大的改進(jìn)是大小寫(xiě)轉(zhuǎn)換功能。
4.自定義命名了支持
mb_ereg_*
函數(shù)現(xiàn)在支持命名捕捉。像mb_ereg()
這樣的匹配函數(shù)現(xiàn)在將使用它們的組號(hào)和名稱(chēng)返回指定的捕獲,類(lèi)似于PCRE:
<?php mb_ereg('(?<word>\w+)', '國(guó)', $matches); // => [0 => "國(guó)", 1 => "國(guó)", "word" => "國(guó)"]; ?>
另外,mb_ereg_replace()
現(xiàn)在支持\k<>和\k "
符號(hào)來(lái)引用替換字符串中的指定捕獲:
<?php mb_ereg_replace('\s*(?<word>\w+)\s*', "_\k<word>_\k'word'_", ' foo '); // => "_foo_foo_" ?>
\k<>和\k "
也可用于編號(hào)引用,也可用于大于9的組號(hào)。
PHP7.4新特性
1.類(lèi)型屬性
類(lèi)屬性現(xiàn)在支持類(lèi)型聲明。
<?php class User { public int $id; public string $name; } ?>
上面的示例將強(qiáng)制執(zhí)行$user->id
只能賦給整數(shù)值,而$user->name
只能賦給字符串值。
2.箭頭函數(shù)
箭頭函數(shù)為使用隱式按值范圍綁定定義函數(shù)提供了一種簡(jiǎn)寫(xiě)語(yǔ)法。
<?php $factor = 10; $nums = array_map(fn($n) => $n * $factor, [1, 2, 3, 4]); // $nums = array(10, 20, 30, 40); ?>
3.限制返回類(lèi)型和參數(shù)型逆變
<?php class A {} class B extends A {} class Producer { public function method(): A {} } class ChildProducer extends Producer { public function method(): B {} } ?>
只有在使用自動(dòng)加載時(shí),才可以使用全方差支持。在單個(gè)文件中,只有非循環(huán)類(lèi)型引用是可能的,因?yàn)樗蓄?lèi)在被引用之前都必須是可用的。
4.Null 合并賦值運(yùn)算符
<?php $array['key'] ??= computeDefault(); // is roughly equivalent to if (!isset($array['key'])) { $array['key'] = computeDefault(); } ?>
5.合并數(shù)組新方式
<?php $parts = ['apple', 'pear']; $fruits = ['banana', 'orange', ...$parts, 'watermelon']; // ['banana', 'orange', 'apple', 'pear', 'watermelon']; ?>
6.數(shù)值文字分隔符
<?php 6.674_083e-11; // float 299_792_458; // decimal 0xCAFE_F00D; // hexadecimal 0b0101_1111; // binary ?>
7.弱引用
弱引用允許程序員保留對(duì)對(duì)象的引用,而不阻止對(duì)象被銷(xiāo)毀。
如果有不懂的地方請(qǐng)留言,SKY8G網(wǎng)站編輯者專(zhuān)注于研究IT源代碼研究與開(kāi)發(fā)。希望你下次光臨,你的認(rèn)可和留言是對(duì)我們最大的支持,謝謝!
推薦學(xué)習(xí):《PHP視頻教程》
The above is the detailed content of Quickly understand the new features of each version of PHP7.X. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

User voice input is captured and sent to the PHP backend through the MediaRecorder API of the front-end JavaScript; 2. PHP saves the audio as a temporary file and calls STTAPI (such as Google or Baidu voice recognition) to convert it into text; 3. PHP sends the text to an AI service (such as OpenAIGPT) to obtain intelligent reply; 4. PHP then calls TTSAPI (such as Baidu or Google voice synthesis) to convert the reply to a voice file; 5. PHP streams the voice file back to the front-end to play, completing interaction. The entire process is dominated by PHP to ensure seamless connection between all links.

The core method of building social sharing functions in PHP is to dynamically generate sharing links that meet the requirements of each platform. 1. First get the current page or specified URL and article information; 2. Use urlencode to encode the parameters; 3. Splice and generate sharing links according to the protocols of each platform; 4. Display links on the front end for users to click and share; 5. Dynamically generate OG tags on the page to optimize sharing content display; 6. Be sure to escape user input to prevent XSS attacks. This method does not require complex authentication, has low maintenance costs, and is suitable for most content sharing needs.

To realize text error correction and syntax optimization with AI, you need to follow the following steps: 1. Select a suitable AI model or API, such as Baidu, Tencent API or open source NLP library; 2. Call the API through PHP's curl or Guzzle and process the return results; 3. Display error correction information in the application and allow users to choose whether to adopt it; 4. Use php-l and PHP_CodeSniffer for syntax detection and code optimization; 5. Continuously collect feedback and update the model or rules to improve the effect. When choosing AIAPI, focus on evaluating accuracy, response speed, price and support for PHP. Code optimization should follow PSR specifications, use cache reasonably, avoid circular queries, review code regularly, and use X

1. Maximizing the commercial value of the comment system requires combining native advertising precise delivery, user paid value-added services (such as uploading pictures, top-up comments), influence incentive mechanism based on comment quality, and compliance anonymous data insight monetization; 2. The audit strategy should adopt a combination of pre-audit dynamic keyword filtering and user reporting mechanisms, supplemented by comment quality rating to achieve content hierarchical exposure; 3. Anti-brushing requires the construction of multi-layer defense: reCAPTCHAv3 sensorless verification, Honeypot honeypot field recognition robot, IP and timestamp frequency limit prevents watering, and content pattern recognition marks suspicious comments, and continuously iterate to deal with attacks.

PHP does not directly perform AI image processing, but integrates through APIs, because it is good at web development rather than computing-intensive tasks. API integration can achieve professional division of labor, reduce costs, and improve efficiency; 2. Integrating key technologies include using Guzzle or cURL to send HTTP requests, JSON data encoding and decoding, API key security authentication, asynchronous queue processing time-consuming tasks, robust error handling and retry mechanism, image storage and display; 3. Common challenges include API cost out of control, uncontrollable generation results, poor user experience, security risks and difficult data management. The response strategies are setting user quotas and caches, providing propt guidance and multi-picture selection, asynchronous notifications and progress prompts, key environment variable storage and content audit, and cloud storage.

PHP ensures inventory deduction atomicity through database transactions and FORUPDATE row locks to prevent high concurrent overselling; 2. Multi-platform inventory consistency depends on centralized management and event-driven synchronization, combining API/Webhook notifications and message queues to ensure reliable data transmission; 3. The alarm mechanism should set low inventory, zero/negative inventory, unsalable sales, replenishment cycles and abnormal fluctuations strategies in different scenarios, and select DingTalk, SMS or Email Responsible Persons according to the urgency, and the alarm information must be complete and clear to achieve business adaptation and rapid response.

PHPisstillrelevantinmodernenterpriseenvironments.1.ModernPHP(7.xand8.x)offersperformancegains,stricttyping,JITcompilation,andmodernsyntax,makingitsuitableforlarge-scaleapplications.2.PHPintegrateseffectivelyinhybridarchitectures,servingasanAPIgateway

Select the appropriate AI voice recognition service and integrate PHPSDK; 2. Use PHP to call ffmpeg to convert recordings into API-required formats (such as wav); 3. Upload files to cloud storage and call API asynchronous recognition; 4. Analyze JSON results and organize text using NLP technology; 5. Generate Word or Markdown documents to complete the automation of meeting records. The entire process needs to ensure data encryption, access control and compliance to ensure privacy and security.
