
Modern PHP Cheatsheet
PHP is far from dead. We can see the language itself maturing and the amazing tools and frameworks at the same time. There are lots of great articles and videos comparing and showcasing the new features added in PHP 8 but, recently I cam across a github repo doing just that, showcasing the new features and their implementation.
Let take a look at this example of function default parameter value:
You can set default value to your function parameters:
1function myFunction($param = 'foo')2{3 return $param;4}5$a = myFunction();6// $a = 'foo'7 8$b = myFunction('bar');9// $b = 'bar'
But if you send null or an undefined property, default value won't be used:
1function myFunction($param = 'foo')2{3 return $param;4}5$a = myFunction(null);6// $a = null7 8$b = myFunction($undefined); // PHP Warning: Undefined variable $undefined9// $b = null
For a complete list of features and implementations, visit the github repo.

Comments

Marian Pop
marian@laravelmagazine.comPHP / Laravel Developer. Writing and maintaining @LaravelMagazine. Host of "The Laravel Magazine Podcast". Pronouns: vi/vim.