-
-
Save tommcfarlin/abfec39e0a65e272d7856d88a7ae2fd7 to your computer and use it in GitHub Desktop.
[PHP] Using Nullable Return Types in PHP
This file contains 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 | |
namespace Acme; | |
class Post { | |
// Attributes, Constructor, and Functions here. | |
} |
This file contains 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 | |
namespace Acme; | |
class PostManager { | |
private $post; | |
// Constructor and other Functions here. | |
public function getPost(): Post | |
{ | |
return $this->post; | |
} | |
} |
This file contains 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 | |
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