<?php
class Point {
public function __construct(
private float $x,
private float $y) {}
public function getX(): float { return $this->x; }
public function getY(): float { return $this->y; }
}
Safe properties
<?hh
new Point(); // error
new Point(0, 0); // OK
Trait requirements
<?hh
class DrupalEntity {
public function getUuid(): string {
return '…';
}
}
trait CacheFlusher {
require extends DrupalEntity;
public function getCacheId(): string {
return 'cacheId:' . $this->getUuid();
}
}
More data types
string/int/float/enum/…
Enum
<?hh
enum gender = {
male = 1;
female = 0;
}
function print_gender(gender $gender): string {
return 'Your are :'
. $gender ? 'male' : 'female'
;
}