What are the features in PHP7

零下一度
Release: 2023-03-10 17:20:02
Original
1161 people have browsed it

type declaration< h2>

look at the code and it’s clear a glance. < p>

class person {     public function age(int $age) : string     {         return 'age is ' . $age;     } }< pre>
copy after login< div>< div>

namespace use keyword batch

non-mixed mode< >use publishers\packt\{ book, ebook, video}; use function publishers\packt\{ getbook, savebook }; use const publishers\packt\{ count, key };<

mixed >use publishers\packt\{     book,     ebook,     video,     function getbook,     function savebook,     const count,     const key };<

composite     paper\book,     electronic\ebook,     media\video

anonymous class<

anonymous classes are declared used same time have all functions of other classes. the difference is that anonymous no name. syntax as follows: >new class(argument) { definition };<

anonymous names, but within php, they will be assigned globally unique name in memory reference address table. em>< >$name =" new class('You') {"     public function __construct($name)         echo $name; can inherit parent its methods. >class packt     protected $number;     public function __construct()         echo 'parent construct';     public function getnumber() : float         return $this->number; } $number =" new class(5) extends Packt"     public function __construct(float $number)         parent::__construct();         $this->number =" $number;" }; echo $number->getnumber();< interfaces. >interface publishers     public function __construct(string name, string address);     public function getname();     public function getaddress(); class packt     protected $name;     protected $address;     public function ... $info =" new class('name', 'address') extends Packt implement Publishers"     public function __construct(string $name, string $address)         $this->name =" $name;"         $this->address =" $address;"     public function getname() : string         return $this->name;     public function getaddress() : string         return $this->address; echo $info->getname() . ' ' . $info->getaddress();< nested class. >class math     public $first_number =" 10;"     public $second_number =" 10;"     public function add() : float         return $this->first_number + $this->second_number;     public function mutiply_sum()         return new class() extends math         {             public function mutiply(float $third_number) : float             {                 return $this->add() * $third_number;             }         }; $math =" new Math();" echo $math->mutiply_sum()->mutiply(2);<

abandon old-fashioned constructor<

starting from php4, constructor declare itself by naming it consistent with in php7, still possible to this way. use, deprecated, output deprecated information deprecated: methods their not constructors future version php; packt has ...< code>, it recommended __construct()< code> php7.

throwable interface<

starting fatal errors program intercepted. php7 provides throwable interface, exceptions inherited interface.

error<

now most error conditions throw an instance, similar intercepted exceptions, instances try catch. >try     ... } catch(error $e)     echo $e->getmessage();

in some situations, only sub-instances thrown, such typeerror, divisionbyzeroerror, parseerror, etc.

<=">Operator

"

<=">The" operator ="=," < >< code>the three comparison operators packaged together. specific usage rules follows.

returns 0 when both sides equal
-1 left side less than right 1 greater p>< blockquote>

null merge operator

??< combination returned directly first operand exists, otherwise second returned. >$title =" $post['title'] ?? NULL;" $title =" $post['title'] ?? $get['title'] ?? 'No title';

uniform variable syntax< >$first =" ['name' => 'second'];" $second =" 'two';" echo $$first['name']; echo ${sfirst['name']};   php7 ... echo $object->$methods['title']; echo $object->{$methods['title']};   php7<

the main reason parsing method different previous php. just add curly braces just like above code, report error.

constant array< php5.6, constant arrays using const< keyword. through define< function. initialize. >const stores =" ['en', 'fr', 'ar']; // php5.6" define('stores', ['en', 'fr', 'ar']);   php7<

default value switch<

before multiple default values ​​were allowed switch statement. there one value, level occur. mistake. >  php7之前 switch (true) {     case 'value':         # code...         break;     default:  php7

option array session_start function< session_start() function must called session, parameters passed, session-related configurations they php.ini file. you pass parameter options calling these setting override session configuration php.ini. >session_start([     'cookie_lifetime' ="> 3600,"     'read_and_close' ="> true" ]);<

unserialize introduces filters<

unserialize() deserialize any type object without filter items, which unsafe. filters unserialize(), deserialization types objects default. >$result =" unserialize($object, ['allowed_classes' => ['Book', 'Ebook']]);

The above is the detailed content of What are the features in PHP7. For more information, please follow other related articles on the PHP Chinese website!

type>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!