Why Use Isset Check For The Propertis That We Sure Is Null

hi im new to yii, i am reading your book and i have confusing problem below is a peace of the book code in

issueController.php


/**

 * Protected method to load the associated Project model class

 * @project_id the primary identifier of the associated Project

 * @return object the Project data model based on the primary key 

 */

protected function loadProject($projectId)	 

{

	//if the project property is null, create it based on input id

	if($this->_project===null)

	{

		$this->_project=Project::model()->findbyPk($projectId);

		if($this->_project===null)

        	{

			throw new CHttpException(404,'The requested project does not exist.'); 

		}

	}


	return $this->_project; 

}

and my question is why we use


if($this->_project===null)

i think its useless. is it not better to write this? :




/**

 * Protected method to load the associated Project model class

 * @project_id the primary identifier of the associated Project

 * @return object the Project data model based on the primary key 

 */

protected function loadProject($projectId)	 

{

	$this->_project=Project::model()->findbyPk($projectId);

	if($this->_project===null)

        {

		throw new CHttpException(404,'The requested project does not exist.'); 

	}


	return $this->_project; 

} 



With your approach you execute a db query every time you call loadProject(), even if you already have one project loaded. The if-clause does nothing to performance, while the sql query could take a long time.

Yeah, Tropi is right. :rolleyes: