开发者

Is there a magic class function that can get a class constructor to take arguments like an associative array?

I have some code that looks something like this:

<?
    $addr = array("city" => $city, 
        "streetname" => $streetname,
 开发者_JAVA技巧       "housenumber" => $housenumber);

    $address = new address($addr);
?>

This just seems slightly redundant to me. Could I write the address to class to take this constructor?

<?
    $address = new address("city" => $city, 
        "streetname" => $streetname,
        "housenumber" => $housenumber);
?>

(Yes I know I could create the array between the parenthesis of the constructor, I'm just curious)


That is reminiscent of an idea called named parameters (seen in Python, Objective-C and C#), which PHP unfortunately doesn't support, nor do its developers plan to add support for anytime.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜