Jump to content

Handle Null Argument


TomTees

Recommended Posts

How do I make my constructor work when I don't pass in an argument.  That is, it should efault to null.

 

	class Something{
	private $type=null;

	public function __construct($t){
		$this->type = $t;
	}

	public function setSomething($t){
		$this->type = $t;
	}

	public function getSomething(){
		if (is_null($this->type)) {
			return "None for you!";
		} else {
			return "Something is " . $this->type . ".";
		}
	}
}

 

 

TomTees

 

Link to comment
https://forums.phpfreaks.com/topic/214833-handle-null-argument/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.