PHP 8.0.0. Aceasta versiune marcheaza cea mai recenta versiune majora a limbajului PHP si vine cu numeroase imbunatatiri si functii noi, cum ar fi:

- Union Types
- Named Arguments
- Match Expressions
- Attributes
- Constructor Property Promotion
- Nullsafe Operator
- Weak Maps
- Just In Time Compilation

Named arguments

htmlspecialchars($string, double_encode: false);

Attributes

#[Route("/api/posts/{id}", methods: ["GET", "HEAD"])]
class User
{

Constructor property promotion

class Point {
  public function __construct(
    public float $x = 0.0,
    public float $y = 0.0,
    public float $z = 0.0,
  ) {}
}

Union types

class Number {
  public function __construct(
    private int|float $number
  ) {}
}

new Number('NaN'); // TypeError

Match expression

echo match (8.0) {
  '8.0' => "Oh no!",
  8.0 => "This is what I expected",
};
//> This is what I expected

Nullsafe operator

$country = $session?->user?->getAddress()?->country;

Saner string to number comparisons

0 == 'foobar' // false

Consistent type errors for internal functions

strlen([]); // TypeError: strlen(): Argument #1 ($str) must be of type string, array given

array_chunk([], -1); // ValueError: array_chunk(): Argument #2 ($length) must be greater than 0

Other syntax tweaks and improvements

Allow a trailing comma in parameter lists RFC and closure use lists RFC
Non-capturing catches RFC
Variable Syntax Tweaks RFC
Treat namespaced names as single token RFC
Throw is now an expression RFC
Allow ::class on objects RFC

New Classes, Interfaces, and Functions

Weak Map class
Stringable interface
str_contains(), str_starts_with(), str_ends_with()
fdiv()
get_debug_type()
get_resource_id()
token_get_all() object implementation

Source: php.net

  • What is your reaction?
  • powered by Verysign
  • like gnulinux.ro
    Like
  • unmoved gnulinux.ro
    Unmoved
  • amused gnulinux.ro
    Amused
  • excited gnulinux.ro
    Excited
  • angry gnulinux.ro
    Angry
  • sad gnulinux.ro
    Sad
TENDINTA  |  GParted 1.3.0 includes improvements, bug fixes, and updates
FlorinM                   gnulinux.ro
FlorinM
Utilizator Linux - Solus OS, pasionat de calatorii.
2303 articole
In context



  • Comment
  • powered by Verysign

Nici un comentariu inca. Fii primul!