PHP Versions Upgradation - What's New vs Old Version

Page 1

PHP Versions Upgradation -

What's New vs Old Version

PHP's frequent upgrades to patch issues and provide new features are its biggest advantages. PHP 8.2 is coming. It may convince everyone to switch to PHP 8. Let's discuss PHP 8.2's benefits for developers. First, let's review PHP's history.

8.0 Released in November 2020, PHP 8.0 brought us the best features yet, which includes: Union types Match expression Nullsafe operator Attributes Constructor property promotion Named arguments htmlspecialchars ($string,double encode: false); class Number { public function __construct( private int|float $number ) {} } new Number('NaN'); // TypeError echo match (8.0) { '8.0' => "Oh no!", 8.0 => "This is what I expected", }; //> This is what I expected $country = $session?>user?->getAddress()?>country; class PostsController { #[Route("/api/posts/{id}", methods: ["GET"])] public function get($id) { /* ... */ } } class Point { public function __construct( public float $x = 0.0, public float $y = 0.0, public float $z = 0.0, ) {} }
8.1 Released in November 2021, PHP 8.1 brought us the best features yet, which includes: New in initializers Pure Intersection Types Fibers Enumerations Readonly Properties First-class Callable Syntax $foo = $this->foo(...); $fn = strlen(...); class Service { private Logger $logger; public function construct( Logger $logger = new NullLogger(), ) { $this->logger = $logger; } } function count and iterate(Iterator &Countable $value) { foreach ($value as $val) { echo $val; } count($value); } $response = $httpClient>request('https://example. com/'); print json decode($response>getBody()->buffer()) ['code']; enum Status { case Draft; case Published; case Archived; } function acceptStatus(Status $status) {...} class BlogData { public readonly Status $status; public function construct (Status$status) { $this->status = $status; } }
8.2 Released in December 2022, PHP 8.2 brought us the best features yet, which includes: Readonly Classes Redacting The Support For Sensitive Parameter Values True, False, and Null as Standalone Types Disjunctive Normal Form Types Constants in Traits trait Foo { public const CONSTANT = 1; } class Bar { use Foo; } var _dump(Bar::CONSTANT); // 1 var dump(Foo::CONSTANT); // Error readonly class MyClass { public string $myValue, public int $myOtherValue public string $myAnotherValue public int $myYetAnotherValue } function passwords( $publicpassword, #[\SensitiveParameter] $secretpassword ) { throw new \Exception('Error'); } passwords('publicpassword', 'secretpassword'); function alwaysFalse(): false { return false; } // Accepts an object that implements both A and B, // OR an object that implements D. (A&B)|D // Accepts an object that implements C, // OR a child of X that also implements D, // OR null. C|(X&D)|null // Accepts an object that implements all three of A, B, and D, // OR an int, // OR null. (A&B&D)|int|null
How To Upgrade PHP Version Check Your Current Version 01 Contact Web Host Provider 02 Create a Site Backup 03 Update WordPress 04 Switch your PHP Version 05 Check For Errors 06 Updates Themes and Plugins 07 Go Live With the Update 08

PHP is improving in syntax simplification and support for new features with each new version. For More Detailed Features of PHP 8.2 You can read the Full blog on WhatsNewInPHP8.2

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.