PHP in 2020

#History summarized

#PHP’s type system

<?phpdeclare(strict_types=1);final class Foo
{
public int $intProperty = 2;
public ?string $nullableString = null; private Bar $bar; public function __construct(Bar $bar) {
$this->bar = $bar;
}

public function withInt(int $value): self
{
$clone = clone $this;

$clone->intProperty = $value;
return $clone;
}

public function unionTypes(int|float $input): void
{
// Union types will be added in PHP 8
}
}
/** @var int[] */
public array $arrayOfInts = [];

#PHP’s syntax

[$a, $b] = $array;
$value = $object->property ?? 'fallback if null';$value = $array['foo'] ?? "fallback if key doesn't exists";
public function get(string $input): string 
{
return $this->cache[$input] ??= $this->sanitize($input);
}
$a = [/* … */];
$b = [/* … */];
$mergedArray = [...$a, ...$b];
public function get(Foo ...$foos): void
{
foreach($foos as $foo) {
// …
}
}
$this->get(...$arrayOfFoo);
public int $intProperty;
$ids = array_map(fn(Post $post): int => $post->id, $posts);
function make(array $input): Generator
{
foreach ($input as $item) {
yield $this->doSomethingWith($item);
}
}

#PHP’s performance

#Frameworks and ecosystem

#In closing

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store