newbie question: Can D do this?

mta`chrono chrono at
Wed Dec 21 00:36:18 PST 2011

In PHP frameworks often use $option arrays which are some kind of key
value pairs. they are merged with the default valuzes inside the function.

 - you can pass an argument by name
 - you only need to pass those who needed.

 - hash arrays

it should be possible to create a similar method in d. but I really
don't like this solution in d. it feels bad and looks ugly.


   'firstname' => 'John',
   'country' => 'France',
   'order' => 'asc'

class Model
    function query($options = array())
        // merge with defaults
        $options = array_merge(array(
            'deep' => true,
            'order' => 'desc',
            'type' => 'sql',
            'backend' => 'mysql'
        ), $options);



More information about the Digitalmars-d-learn mailing list