3 ms·
Article with an overview of the changes: https://stitcher.io/blog/new-in-php-8 https://stitcher.io/blog/new-in-php-8 Some highlights are union types, a JIT com
by toupeira 6y ago
Article with an overview of the changes: https://stitcher.io/blog/new-in-php-8 https://stitcher.io/blog/new-in-php-8
Some highlights are union types, a JIT compiler, named arguments, annotations, and match expressions.
The approach to named arguments is interesting. It's nice that you don't have to change the signature of existing functions, but the downside seems to be that you can't enforce the usage of named arguments on callers, as in other languages like Ruby and Python where keyword arguments need to be declared as such.
function foo(string $a, string $b, ?string $c = null, ?string $d = null)
{ /* … */ }
foo(
b: 'value b',
a: 'value a',
d: 'value d',
);
- Denvercoder9 6y ago> Python where keyword arguments need to be declared as such. In Python you don't need to explicitly declare keyword arguments either (though it is possible). This is perfectly valid and working: def foo(a: str, b: int, c: bool=None, d: float=None): pass foo(b=5, a='something', d=3.0) # is equivalent to foo('something', 5, None, 3.0)
- toupeira 6y agoThanks, TIL!