Phetolelo ea puo ea lenaneo la PHP 8.1

Kamora selemo sa nts'etsopele, ho ile ha hlahisoa tokollo ea puo ea lenaneo la PHP 8.1. Lekala le lecha le kenyelletsa letoto la likarolo tse ncha, hammoho le liphetoho tse 'maloa tse senyang ho lumellana.

Lintlafatso tsa bohlokoa ho PHP 8.1:

  • Ts'ehetso e ekelitsoeng bakeng sa lipalo, mohlala, joale u ka sebelisa lihahi tse latelang: enum Status { case Pending; nyeoe E sebetsang; case Archived; } sehlopha sa Post {mosebetsi oa sechaba __construct( poraefete Boemo $ boemo = Boemo:: E sa ntse e le teng; ) {} mosebetsi oa sechaba setStatus(Boemo ba $ boemo): lefeela {// … } } $ post-> setStatus(Boemo:: E sebetsa);
  • Ts'ehetso e ekelitsoeng bakeng sa likhoele tse bobebe tse bitsoang Fibers, tse u lumellang ho laola likhoele tsa polao maemong a tlase. Tšehetso ea fiber e reretsoe ho eketsoa ho meralo ea Amphp le ReactPHP. $ fiber = Fiber e ncha (mosebetsi (): lefeela {$ valueAfterResuming = Fiber:: emisa ('kamora ho emisa'); // ... }); $valueAfterSuspending = $fiber->qala(); $ fiber-> qala hape ('kamora ho qala hape');
  • Ts'ebetsong ea cache ea khoutu ea ntho (opcache) e ntlafalitsoe, e etsa hore ho khonehe ho boloka tlhahisoleseding e mabapi le lefa la sehlopha. Ntlafatso e entse hore ho khonehe ho eketsa ts'ebetso ea lits'ebetso tse ling ka 5-8%. Lintlafatso tse ling li kenyelletsa ntlafatso ea ts'ebetso ea JIT, ts'ebetsong ea ts'ehetso ea JIT bakeng sa meralo ea ARM64 (AArch64), ho potlakisa ho rarolla mabitso, ho ntlafatsa lilaebrari tsa timelib le ext/date, ts'ebetso e eketsehileng ea serialization le ts'ebetso ea deserialization, optimization ea get_declared_classes(), phatloha () , strnatcmp() mosebetsi, strnatcmp(), dechex(). Ka kakaretso, ho na le keketseho ea 23.0% ea ts'ebetso ea Symfony Demo, le 3.5% bakeng sa WordPress.
  • Opereishene ea ho phutholla ka hare ho lihlopha "...$var", e lumellang hore ho behoe li-arrays tse teng ha li hlalosa sehlopha se secha, se ekelitsoe ho tšehetsa linotlolo tsa likhoele (pele ho ne ho tšehetsoa li-identifiers tsa digital). Mohlala, joale u ka sebelisa khoutu: $array1 = [“a” => 1]; $array2 = ["b" => 2]; $array = [“a” => 0, …$array1, …$array2]; var_dump($array); // ["a" => 1, "b" => 2]
  • E lumelloa ho sebelisa "ncha" lentsoe la sehlooho ho li-initiator, joalo ka litlhaloso tsa ts'ebetso e le paramethara ea kamehla kapa litšobotsing tsa likhang. sehlopha sa MyController {ts'ebetso ea sechaba __construct(private Logger $logger = NullLogger e ncha (), ) {}}
  • Hoa khoneha ho tšoaea thepa ea sehlopha bakeng sa phihlello ea ho bala feela (boitsebiso bo nang le thepa e joalo bo ka ngoloa hanngoe feela, ka mor'a moo bo ke ke ba fumaneha bakeng sa phetoho). class PostData {mosebetsi wa setjhaba __construct(mohala o balwang ke setjhaba feela $title, letsatsi le balwang feela la setjhaba DateTimeImmutable $date,) {} } $poso = Post e ncha('Title', /* … */); $ poso-> sehlooho = 'Tse ling'; > Phoso: Ha e khone ho fetola thepa e baloang feela Post::$title
  • Syntax e ncha e kentsoe ts'ebetsong bakeng sa lintho tse lelekoang - ho koala hona joale ho ka etsoa ka ho bitsa tšebetso le ho fetisa boleng "..." joalo ka khang (ie myFunc(...) sebakeng sa Closure::fromCallable('myFunc ')): tshebetso foo (int $a, int $b) { /* … */ } $foo = foo(…); $foo(a: 1, b: 2);
  • E kentse tšehetso e felletseng bakeng sa mefuta ea mateano, e u lumellang ho theha mefuta e mecha ka ho kopanya e teng. Ho fapana le mefuta ea mekhatlo ea basebetsi, e hlalosang pokello ea mefuta e 'meli kapa ho feta, mefuta ea matekoane e hloka hore ho be le mefuta e sa tšoaneng e thathamisitsoeng, empa mefuta eohle e boletsoeng ka har'a sete e lokelang ho tlatsoa. mosebetsi hlahisaSlug(HasTitle&HasId $post) {khutlisa strtolower($post->getTitle()) . $ poso-> getId(); }
  • Ho na le mofuta o mocha "le ka mohla" o ka sebelisoang ho tsebisa bahlahlobi ba tsitsitseng hore ts'ebetso e tla emisa ts'ebetso ea lenaneo, mohlala ka ho etsa mokhelo kapa ho etsa mosebetsi oa ho tsoa. function dd(motsoako oa $input): ha ho mohla {tsoa; }
  • Ho entsoe tlhahiso e ncha ea tšebetso array_is_list, e u lumellang hore u tsebe hore linotlolo tsa sehlopha li hlophisitsoe ka tatellano ea lipalo tse ntseng li eketseha, ho tloha ho 0: $list = [“a”, “b”, “c”]; array_is_list(lethathamo la $); // nnete $notAList = [1 => “a”, 2 => “b”, 3 => “c”]; array_is_list ($ notAList); // bohata $alsoNotAList = ["a" => "a", "b" => "b", "c" => "c"]; array_is_list($alsoNotAList); // bohata
  • Hona joale u ka sebelisa "final" keyword ho thibela hore likarolo tsa sehlopha sa batsoali li se ke tsa hlakoloa. sehlopha Foo {final public const X = "foo"; } Sehlopha sa Bar se atolosa Foo {public const X = "bar"; > Phoso e bolaeang: Bar::X ha e khone ho qhelela ka thōko Foo::X }
  • Mesebetsi ea fsync le fdatasync e reretsoe ho qobella liphetoho ho bolokoa ho cache ea disk. $file = fopen("sample.txt", "w"); fwrite($file, "Litaba tse ling"); haeba (fsync($file)) {echo "Faele e phehelletsoe ka katleho ho disk."; } fclose($file);
  • E ekelitse bokhoni ba ho sebelisa li-prefixes "0o" le "0O" bakeng sa linomoro tsa octal, ho phaella ho "0" e sebelisitsoeng pele. 016 === 0o16; // nnete 016 === 0O16; // nnete
  • Ho etsoa tlhahiso ea ho fokotsa tšebeliso ea $ GLOBALS ka mokhoa o ikhethileng, e leng se tla lebisa ho tlōlo ea ho lumellana ha morao, empa e tla etsa hore ho khonehe ho potlakisa ts'ebetso ka li-arrays. Ka mohlala, monyetla oa ho thibela ho ngolla $ GLOBALS le ho fetisa $ GLOBALS ka pointer ho ntse ho nahanoa. Tlhahlobo ea liphutheloana tse 2000 e bonts'itse hore ke tse 23 feela tsa tsona tse tla angoa ke phetoho ena. Ka mohlala, haeba tlhahiso e amohetsoe, 8.1 e ke ke ea hlola e tšehetsa lipolelo tse kang: $GLOBALS = []; $GLOBALS += []; $GLOBALS =& $x; $x =& $GLOBALS; e sa hlophisoang($ GLOBALS); ka_ref($GLOBALS);
  • Mekhoa ea ka hare joale e lokela ho khutlisa mofuta o nepahetseng. Ho PHP 8.1, ho khutlisa mofuta o sa lumellaneng le phatlalatso ea mosebetsi ho tla hlahisa temoso, empa ho PHP 9.0 temoso e tla nkeloa sebaka ke phoso.
  • Mosebetsi o ile oa tsoela pele ho fetisetsa mesebetsi ho tloha ho sebelisa lisebelisoa ho ea ho ho laola lintho. Mesebetsi ea finfo_* le imap_* e fetiselitsoe ho lintho.
  • Ho fetisa litekanyetso tse se nang thuso e le likhang tsa mesebetsi ea ka hare e tšoailoeng e ke keng ea senyeha ho tlositsoe. Ho PHP 8.1, ho sebelisa li-constructs tse kang str_contains("string", null) ho tla lebisa temoso, le ho PHP 9 phoso.
  • Tšehetso e ekelitsoeng bakeng sa MurmurHash3 le xxHash hashing algorithms.

Source: opennet.ru

Eketsa ka tlhaloso