Class works without declaring variables?

oop, php

Solution

Every object in PHP can get members w/o declaring them:

$mycar = new car;
$mycar->model = "Mercedes";
echo $mycar->check_model(); # Good car

That's PHP's default behaviour. Those are public. See manual.

Problem

I'm learned php as functional and procedure language. Right now try to start learn objective-oriented and got an important question. I have code: ``` class car { function set_car($model) { $this->model = $model; } function check_model() { if($this->model == "Mercedes") echo "Good car"; } } $mycar = new car; $mycar->set_car("Mercedes"); echo $mycar->check_model(); ``` Why it does work without declaration of $model? `var $model;` in the begin? Because in php works "auto-declaration" for any variables? I'm stuck

Original source