[oclug] PHP instance name -lunch theme

todd.clattenburg at sdc-dsc.gc.ca todd.clattenburg at sdc-dsc.gc.ca
Thu Jun 17 12:27:30 EDT 2004


That's a drag, it seems that:

$pepperoni = new topping("pepperoni","crispy and spicy"); 

is completely redundant. 

Thanks.

---------------------------------------------------------------------|
Todd Clattenburg
Programmer / Analyst
Todd.Clattenburg at sdc-dsc.gc.ca


-----Original Message-----
From: oclug-bounces at lists.oclug.on.ca [mailto:oclug-bounces at lists.oclug.on.ca] On Behalf Of Mike Thomas
Sent: Thursday, June 17, 2004 12:18 PM
To: General Membership Discussion List
Subject: Re: [oclug] PHP instance name -lunch theme


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");
>
>Now I want to be able to loop through all of the toppings, and
>print out something like: 
>
>	pepperoni - crispy and spicy
>	cheese - ooey gooey
>
>My question is, is there a function in php to pull out the
>instance name of a class, or do I have to have a 'name' property
>of each class, and 'redundantly' populate it in each instance? 
>  
>

 There is really no such thing as an instance name.  As you suggest, you 
would need to have a instvar (property) called name to hold onto that 
sort of information. In the contructor for the class you would then set 
the bame of $this->$name to the parameter supplied to the contructor.

 Mike.
-- 
OCLUG general discussion list
OCLUG at lists.oclug.on.ca
http://www.oclug.on.ca/mailman/listinfo/oclug



More information about the OCLUG mailing list