RE: [SMARTY] assign_by_ref() and append_b

From: Date: Sat, 03 Aug 2002 13:13:47 +0000
Subject: RE: [SMARTY] assign_by_ref() and append_b
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5574@lists.php.net to get a copy of this message
> -----Original Message----- > From: Ferdinand Beyer [mailto:fbeyer@clickhand.de] > Sent: Saturday, August 03, 2002 9:02 AM > To: Rod Kreisler > Subject: RE: Re[2]: Sv: Re: [SMARTY] assign_by_ref() and append_by_ref() > > > On 3 Aug 2002 at 8:32, Rod Kreisler wrote: > > > To do this you don't need function overloading or > > allow_call_time_pass_reference. > > > > function assign($name,&$value,$use_ref=false) > > { > > if ($use_ref) > > { > > // need to keep reference > > $this->_tpl_vars[$name] = &$value; > > } > > else > > { > > // need to dereference > > $this->_tpl_vars[$name] = $value; > > } > > } > > > > This would be backward compatible AND allow passing of any variable (not > > just objects) as a reference. > > Be careful. Your example will trigger an error when called like > $smarty->assign('var', 'direct String'). Have you tested it? > Good point. It wouldn't be backward compatible. I never pass string literals to assign() so didn't think about that... > Your function definition > > function assign($name, &$value) > { > } > > _does_ require a variable reference to be passed as $value (due to > & operator). Yes. That's the point. What are you saying? >Furthermore, assign()ing arrays won't be possible. Why? You > cannot use default values with references: > > function assign($name, &$value = null) > > is not allowed. Not currently (to be supported in Zend 2). However, that's not in the example. > > -- > Ferdinand Beyer > <fbeyer@clickhand.de> > > > >

« previous php.smarty.general (#5574) next »