Passing flags to functions
| From: | Andrei Zmievski | Date: | Tue, 06 Jun 2000 21:05:58 +0000 |
| Subject: | Passing flags to functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-20383@lists.php.net to get a copy of this message | ||
I'd like to start a discussion on working out a generalized way of
passing flags to internal PHP functions. I've often found myself writing
a function and having to anticipate that it might need to accept some
flags to affect its operation, and it was not immediately clear how
those flags should be accessed. This is a bigger problem when you start
working with functions that take optional arguments, because if you want
to add an argument for flags you'll have to stick it at the end and make
your users pass all intermediate arguments as well, non-required as they
are.
For example, I'd like to extend preg_replace to take a couple more flags
that will its operation. Some of those flags are mutually exclusive,
i.e. you can't specify two of them at the same time. So, what would be
the way to pass them - using bitwise | (or)? This makes it hard to have
groups of related flags that are mutually exclusive. Sticking them all
into a 'flags array'? Seems a bit messy.
Another question is how to parse those flags in a general way. I confess
I don't have solutions currently, but that's why I wanted to initiate
the discussion. Perhaps the answer lies in keyword arguments or
somewhere else.
-Andrei