开发者

What is it called when I instantiate an object in PHP and then declare variables inside that object?

开发者 https://www.devze.com 2022-12-17 22:03 出处:网络
I know this is not great practice, but I need a definition in order 开发者_高级运维to get my real question answered.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消