Pilipo
Pilipo

Reputation: 97

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. :)

Upvotes: 2

Views: 106

Answers (3)

Alix Axel
Alix Axel

Reputation: 154603

You're creating object properties (variables that are part of a class).

Upvotes: 0

Jacob Relkin
Jacob Relkin

Reputation: 163288

Simply put, you are creating and assigning a new instance variable inside of the myCar object.

Upvotes: 2

Tommy
Tommy

Reputation: 1985

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.

Upvotes: 0

Related Questions