Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object initialization.

Status
Not open for further replies.

ngabordh

Programmer
Jun 15, 2003
4
HU
Is it possibile to initialize an object`s properties, with a simple action? I mean I have a class with 5 properties.
For example:

class CClass
{
$one;
$two;
$three;
$four;
$five;
function CClass()
{
$array = array(1,2,3,4,5);
...
}
}

And I`d like to initialize the properties, with the walues contained in the array, but I don`t want to use method below.
$this->one=$array[1];
$this->two=$array[2];
...

I know, there is a get_class_vars() PHP function, which copies the properties keys/values into an array. But I`d like to initialize the properties, with items in an array with a 'for' statement, in a simple step.

Is it possibile in PHP?

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top