Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin tommcfarlin/00-post.php Secret
Last active Jun 20, 2018

Embed
What would you like to do?
[PHP] Using Nullable Return Types in PHP
<?php
namespace Acme;
class Post {
// Attributes, Constructor, and Functions here.
}
<?php
namespace Acme;
class PostManager {
private $post;
// Constructor and other Functions here.
public function getPost(): Post
{
return $this->post;
}
}
<?php
namespace Acme;
class PostManager {
private $post;
// Constructor and other Functions here.
public function getPost(): ?Post
{
if ($this->post === null) {
return null;
}
return $this->post;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.