What is it called when I instantiate an object in PHP and then declare variables inside that object?
I know this is not great practice, but I need a definition in order 开发者_高级运维to get my real question answered.
I have an object like this:
class Car
{
public $wheel;
public $engine;
so on..
}
I instantiate and edit values like thus:
myCar = new Car();
myCar->wheels = 4;
myCar->engine = V8;
What is it called when I do this?:
myCar->brakes = "disc";
It populates the new key and value in the existing object, but I don't know the name for that.
Update: I removed the parentheses. :)
Simply put, you are creating and assigning a new instance variable inside of the myCar
object.
isnt that you created a public variable brakes inside myCar instance on the fly?? http://www.php.net/manual/en/language.oop5.visibility.php
but Class Car doesn't have brakes, so when u new Car again, no brakes.
You're creating object properties (variables that are part of a class).
精彩评论