Created
August 29, 2015 10:16
-
-
Save blar/bc55b1ed2aaa159a9209 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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