Fw: [PHP] Feature?
| From: | Andrey Hristov | Date: | Wed, 26 Sep 2001 11:48:00 +0000 |
| Subject: | Fw: [PHP] Feature? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-68840@lists.php.net to get a copy of this message | ||
Let this be last message in the thread. Thanks for the examples! I'll wait for PHP5. There is
a possibility that this feature will
be in.
Have fun
Andrey Hristov
IcyGEN Corporation
http://www.icygen.com
BALANCED SOLUTIONS
> ----- Original Message -----
> From: <php@alister.dnsalias.com>
> To: <php-general@lists.php.net>
> Sent: Wednesday, September 26, 2001 2:42 PM
> Subject: Re: [PHP] Feature?
>
>
> > On Tue, 25 Sep 2001 09:36:57 -0500, you wrote:
> >
> > >>> <?php
> > >>> function foo($p) { echo $p['fred'] . $p['banana'];
> > >>> }
> > >>> foo(array('fred' => 'hello', 'banana' =>
> > >>> 'world'));
> > >>> ?>
> >
> > >> Yeap, I know that. I thought about this bit of hack but this breaks the
> > >> conception on giving parameters. Also this trick cannot
> > >> solve the problem with default parameters. If I have function with 5
> > >> params and all of them have default values and I want to pass
> > >> value only to the second parameter what I have to do?
> >
> > >Maybe this? A bit verbose, but functional.
> > ><?php
> > >function foo($p)
> > >{
> > > if (empty($p['fred']))
> > > $p['fred'] = 'hello'; // same for banana
> > > echo $p['fred'] . $p['banana'];
> > >}
> > >foo(array('fred' => 'hello', 'banana' =>
> > >'world'));
> > >?>
> > >steve
> >
> > I'm not keen on adding lots of multi-line if statements - I prefer tp
> > put things into arrays where I can. Easier to update them.
> >
> > <?php
> > function foo($p)
> > {
> > $foodefault = array( // prefix matching the name in 'extract'
> > 'foo_fred'=> '<strong>default fred</strong>',
> > 'foo_banana' => '<strong>default
> > bananananana</strong>',
> > );
> > extract ($p, EXTR_PREFIX_ALL, 'foo'); // get params
> > extract ($foodefault, EXTR_SKIP, "foo"); // get defaults
> > echo "$foo_fred / $foo_banana";
> > }
> > echo "Both in place: ";
> > foo(array('fred' => 'hello', 'banana' =>
> > 'world'));
> > echo "<br /> Now with a missing param: ";
> > foo(array('fred' => 'hello'));
> > echo "<br /> Now both missing params: ";
> > foo(array());
> > ?>
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
> >
>