We help IT Professionals succeed at work.

New podcast episode! Our very own Community Manager, Rob Jurd, gives his insight on the value of an online community. Listen Now!

x

Passing a variable as the name of new objects

paulp75
paulp75 asked
on
335 Views
Last Modified: 2008-02-01
I have an object class named Gallery as follows
i would like each of the objects created to be based on a variable
so it would be the name of the object would be $galleryid but trying $$galleryid didnt work,
i would like it to be like this basically
$$galleryid = new Gallery($currentdir)


class Gallery {
function __construct($path)
{
$this->path = $path;

}
function getPath()
{
return $this->path;
}
private $path;

};

what i would like to do, is as my script loops through the directories i would like to have each of them create a new object with the name of $nogalleries which is a variable which is set during the running of the script, as mentioned above

thanks for any help
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2006

Commented:
Hello paulp75,

Or use:

${"gallery".$galleryid} = new Gallery($currentdir);

This would create a $gallery123456 variable.

Alternatively use:
$galleryName = 'gallery'.$galleryid;
$$galleryName = new Gallery($currentdir);

Regards,

Roonaan

Author

Commented:
thanks roonaan. Still just starting with oop with php, so its a steep learning curve, and thats a great method to use.

thanks
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.