[oclug] PHP instance name -lunch theme
sphex at sympatico.ca
Fri Jun 18 01:49:12 EDT 2004
> todd.clattenburg at sdc-dsc.gc.ca wrote:
>> I am trying to access the instance name of an object in PHP. For
>> example, say I have a class called 'topping'.
>> $pepperoni = new topping("crispy and spicy");
>> $cheese = new topping("ooey gooey");
You are confusing
one of your perceptions about 'realworld' pepperoni
with the method used by PHP to refer to digital Objects.
You happen to use the word, "name", in both cases
so you think they are the same thing.
So far as I can see,
'pepperoni' and 'cheese' are not Objects at all. (note below)
Not the Objects you should be programming.
You are associating the String, "crispy and spicy"
with the String, "pepperoni";
and "ooey gooey" with "cheese".
Perhaps, in the back of your mind,
you are thinking "adjective" and "noun".
That is ok, as long as you promise to be careful
and not to believe they are adjectives and nouns.
I guess the Object you really want is a Dictionary,
an indefinite-length List of two-element Lists (tuples).
You could use the Variable named, '$toppings',
to refer to this dictionary,
but you should be careful not to think of "toppings" as its Name.
Useful Methods might be :
additem ("item", "description")
The latter would be what you ought to have asked us for.
The Strings, "pepperoni" and "cheese" are of course Objects,
because Strings are themselves Objects (all Objects are Objects).
In the 'realworld', 'pepperoni' is not an Object, either.
It is a Class, of sorts.
A particular 'piece of pepperoni' would be an Object, of sorts.
(further gratuitous confusion)
You might give your 'dictionary' a 'title'.
No doubt, you will think of its "title" as its "name".
You could have several Instances of Class 'dictionary',
with 'titles' like :
And their Names might be :
I know I have quote-marks in at least two different ways.
Probably, I have misused/confused other Classes of Objects, too.
More information about the OCLUG