Pre-defining Class Variables in PHP (Yii Models)

I was coding in PHP, using the Yii framework. The columns in Yii turn into Model variables. These variables are automatically created by Yii so I don't think I should need to create them. I do not get any errors or warnings on the site when I run the app without the variables pre defined. I have my framework on PHPStorm set to Yii so I was wondering if someone could get me some answers. I apologize if this question has been asked already.

Here is an example. Lets say I have a table in my database.

id  | type  | width | height |
1  | 'input' | 300   | 200    |

And a Model representing that table.

class Form extends CActiveRecord {

In my controller I am going to ask for those variables in the database based off of ID.

class FormController extend CController {
  public function actionIndex() {
    $form_model = new Form;
    $form = $form->findByPK(1);
    $form->id; // PHPStorm warning
    $form->type; // PHPStorm warning
    $form->width; // PHPStorm warning
    $form->height; // PHPStorm warning

In PHPStorm I get warnings as defined in the comments. The warning is that the variables are not defined. So when I go back to my model and add them to the global scope.

class Form extends CActiveRecord {
  public $id;
  public $type;
  public $width;
  public $height;

The warnings fade. I feel like those variables are already created by Yii. but PHPStorm doesn't know that. I am also connected directly to my database so PHPStorm should know that the models and tables all match up. If someone could tell me why this behavior is occurring. Thanks and sorry again if this has already been answered.


Please sign in to leave a comment.