
1. Object attributes now support type declaration
<?php class User {
public int $id;
public string $name;
}
?>
In the above example, $id will be forced to be converted to integer type, $name is String type
Recommended (free):PHP7
2. Arrow function
Now the arrow function will Provide a short syntax for defining functions whose value declarations are unclear within the scope
<?php $factor = 10; $nums = array_map(fn($n) => $n * $factor, [1, 2, 3, 4]); // $nums = array(10, 20, 30, 40); ?>
3, limited return type covariance and parameter type covariance (Google Translate)
The following code will Will run
<?php class A {}
class B extends A {}
class Producer {
public function method(): A {}
}
class ChildProducer extends Producer {
public function method(): B {}
}
?>
Full diff support is only provided when using autoloading. Within a single file, only non-cyclic type references can be used because all classes must be available before being referenced
4, Null merge assignment operator
<?php $array['key'] ??= computeDefault();
// is roughly equivalent to
if (!isset($array['key'])) {
$array['key'] = computeDefault();
}
?>
5, Unpacking inside arrays (Google The translation is to unpack inside the array. See if this is wrong, use English first)
<?php $parts = ['apple', 'pear']; $fruits = ['banana', 'orange', ...$parts, 'watermelon']; // ['banana', 'orange', 'apple', 'pear', 'watermelon']; ?>
6. Numeric character separator
Numeric characters can include underscores between numbers.
<?php 6.674_083e-11; // float 299_792_458; // decimal 0xCAFE_F00D; // hexadecimal 0b0101_1111; // binary ?>
7. Weak references
Weak references allow the programmer to retain a reference to an object that cannot be prevented from being destroyed does not prevent the object from being destroyed.)
8. Allow exceptions __toString()
can now be thrown through __toString() Exceptions, which in previous versions would have resulted in a fatal error, existing string conversions that could have resulted in a fatal error have been converted to throw exceptions.
We will look at the rest of the expansion later
The above is the detailed content of Introducing new features from php7.3 to php7.4. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

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

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

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),





