tags:

views:

44

answers:

3

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

+2  A: 

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

Jacob Relkin
Perfect thanks. Do you know of a way to lock an object down to avoid inadvertent variable loading? The class I have built loads up from a mySql select, but on save it simply iterates through the $_POST to update the table. As I write this, I notice the security issues, but I want a way to lock the object to the existing table fields. Any pointers?
Pilipo
You could use the magic `__set` method, and only allow x variables to be set.
Jacob Relkin
Obviously, this would only work with instance data that is not directly accessible.
Jacob Relkin
Jacob, I could kiss you. That was exactly what I needed! Thanks a ton!
Pilipo
@Pilipo thank you! :)
Jacob Relkin
A: 

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.

Tommy
A: 

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

Alix Axel
i think you meant 'variables that are part of an object', 'variables that are part of a class' would be `static`.
Jacob Relkin