Skip to content

Instantly share code, notes, and snippets.

@blar
Created August 29, 2015 10:16
Show Gist options
  • Save blar/bc55b1ed2aaa159a9209 to your computer and use it in GitHub Desktop.
Save blar/bc55b1ed2aaa159a9209 to your computer and use it in GitHub Desktop.
<?php
class User {
/**
* @var DateTimeInterface
*/
private $birthday;
public function setBirthday(DateTimeInterface $birthday) {
$this->birthday = $birthday;
}
public function getBirthday(): DateTimeInterface {
if(!($this->birthday instanceof DateTimeInterface)) {
throw new RuntimeException('Birthday not set');
}
return $this->birthday;
}
}
$user = new User();
# $user->setBirthday(new DateTime('1980-01-01'));
var_dump($user->getBirthday());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment