Why "on the fly" object property assignement/creation doesn't work?

As the topic i would like to know why i got an exception of property not defined in class when i try in a controller:

public function actionMyAction() {

    $this->headTitle = 'Area Amministrativa';


Cause you need to define it!

Class YOurCOntroller extend CController{

   public headTitle;

   //your functions.


but we all know that we can do that without predeclaring it. It is valid php code

The php magic method __set() was overridden by CComponent::__set() as follows

	public function __set($name,$value)




			return $this->$setter($value);

		else if(strncasecmp($name,'on',2)===0 && method_exists($this,$name))


			// duplicating getEventHandlers() here for performance



				$this->_e[$name]=new CList;

			return $this->_e[$name]->add($value);


		else if(is_array($this->_m))


			foreach($this->_m as $object)


				if($object->getEnabled() && (property_exists($object,$name) || $object->canSetProperty($name)))

					return $object->$name=$value;




			throw new CException(Yii::t('yii','Property "{class}.{property}" is read only.',

				array('{class}'=>get_class($this), '{property}'=>$name)));


			throw new CException(Yii::t('yii','Property "{class}.{property}" is not defined.',

				array('{class}'=>get_class($this), '{property}'=>$name)));


If you wish to set properties "on the fly", then override the __set method of your class to allow it.

what i mean is that the __set method isn’t necessary. It is valid to assign an object property in a method even when it is not predeclared…it is valid php code

and then i quote this from the yii defenitive guide:

Inside the view script, we can access the controller instance using $this. We can thus pull in any property of the controller by evaluating $this->propertyName in the view.

It is valid php code but it’s just the preference of Yii(author) to do so. At this point I’m not sure for what reason it’s done but i like that strictness.