Check if variable is class property is set

I have the following code to create a virtual attribute "mydob".


public function getMyDOB()

{

    return  date('m/d/Y', CDateTimeParser::parse($this->dob, 'yyyy-MM-dd'));

}



The problem is that if $this->dob is undefined (such as when I am creating instead of updating), this returns the date of the Unix epoch. Any ideas on how I can check to see if $this->dob is defined before I return?

It depends on what you want to return if it turns out to be undefined. It would go like this:




	public function getMyDOB()

	{

		if ($this->_mydob === null && $this->dob !== null)

		{

			$this->_mydob = date('m/d/Y', CDateTimeParser::parse($this->dob, 'yyyy-MM-dd'));

		}

		return $this->_mydob;

	}



And add ELSEIF in case you wish to have some default value when $this->dob is not defined.

Your suggestion works great. Thanks!

Use the Yii::log() method, in your config/main.php you can configure the log level by adding the "info" level, by default is not set, look at your config/main.php




		'log'=>array(


			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning,info',

				),

			),

		),



Once log is configured you can use it in this way:

[color=#000088]public[/color][color=#000000] [/color][color=#000088]function[/color][color=#000000] getMyDOB[/color]color=#666600[/color][color=#000000]

[/color][color=#666600]{[/color][color=#000000]

Yii::log("My dob is:".[/color][color=#000000]$this[/color][color=#666600]->[/color][color=#000000]dob[/color],"info"); // use the Yii::log    [color=#000088]return[/color][color=#000000]  date[/color][color=#666600]([/color][color=#008800]'m/d/Y'[/color][color=#666600],[/color][color=#000000] [/color][color=#660066]CDateTimeParser[/color][color=#666600]::[/color][color=#000000]parse[/color][color=#666600]([/color][color=#000000]$this[/color][color=#666600]->[/color][color=#000000]dob[/color][color=#666600],[/color][color=#000000] [/color][color=#008800]'yyyy-MM-dd'[/color][color=#666600]));[/color][color=#666600]}[/color]

Where you can find the log file ?

look at: /protected/runtime/application.log