PHP Value Object auto create
Posted
by JonoB
on Stack Overflow
See other posts from Stack Overflow
or by JonoB
Published on 2010-04-28T12:50:10Z
Indexed on
2010/04/28
12:53 UTC
Read the original article
Hit count: 234
Assume that I have a class value object defined in php, where each variable in the class is defined. Something like:
class UserVO {
public $id;
public $name;
}
I now have a function in another class, which is expecting an array ($data).
function save_user($data) {
//run code to save the user
}
How do I tell php that the $data parameter should be typed as a UserVO? I could then have code completion to do something like:
$something = $data->id; //typed as UserVO.id
$else = $data->name; //typed as UserVO.name
I'm guessing something like the following, but this obviously doesnt work
$my_var = $data as new userVO();
© Stack Overflow or respective owner