jQuery style Constructors in PHP

Posted by McB on Stack Overflow See other posts from Stack Overflow or by McB
Published on 2011-01-13T14:48:13Z Indexed on 2011/01/13 14:53 UTC
Read the original article Hit count: 345

Filed under:
|
|

Is there a way to instantiate a new PHP object in a similar manner to those in jQuery? I'm talking about assigning a variable number of arguments when creating the object. For example, I know I could do something like:

...
//in my Class
__contruct($name, $height, $eye_colour, $car, $password) {
...
}

$p1 = new person("bob", "5'9", "Blue", "toyota", "password");

But I'd like to set only some of them maybe. So something like:

$p1 = new person({
    name: "bob",
    eyes: "blue"});

Which is more along the lines of how it is done in jQuery and other frameworks. Is this built in to PHP? Is there a way to do it? Or a reason I should avoid it?

© Stack Overflow or respective owner

Related posts about php

Related posts about oop