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.
精彩评论