Re: Re[2]: Sv: Re: [SMARTY] assign_by_ref() and append_by_ref()
| From: | Ferdinand Beyer | Date: | Sat, 03 Aug 2002 09:29:49 +0000 |
| Subject: | Re: Re[2]: Sv: Re: [SMARTY] assign_by_ref() and append_by_ref() | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5571@lists.php.net to get a copy of this message | ||
On 3 Aug 2002 at 14:52, Hendy Irawan wrote:
> smarty-general,
>
> > Are you sure that they want to discard references in PHP5? I will ask
> I guess not. References will be there forever (for backwards
> compatibility, and for many other useful things, not just for
> objects). But allowing call time pass references is not a good idea
> (at least, for me).
>
> > Please don't connect references automatically with objects - you can
> I agree with you. references are not objects. But in my opinion,
> objects should implicitly be references. This is because, in my
> experience, I've never *copied* an object to any other variable,
> always copy its reference. Even for "new"ing, eg:
>
> $myobj = &new MyClass;
>
> This syntax, is, definitely, very weird.
That's true and that's why the zend guys are working on the new
object model - definetly a very very very great improvement.
> > also use them for other values. So you could assign a string to
> > smarty and change it later without having to call assign() again.
> Yes, using references this way is great. But I guess dual function of
> assign() is not possible until PHP has something called function
> overloading.
I'll explain it below.
>
> > function fetchInto(&$var)
> This function isn't "similar" to assign.
That's true. It's just an example why I want PHP to support
references.
> Doing fetchInto('a string') will give you an error.
So don't use it like this :-)
>
> And if you change the *declaration* of fetchInto(&$var) to
> fetchInto($var) (which is undoubtably useless), and then call
> fetchInto like this:
>
> fetchInto(&$put_my_data_here);
>
> This will work *only* as long as allow-call-time-pass-reference
> configuration is on, which is for now, but not in the future (and
> maybe gone someday).
I don't understand why they should not allow this.
> > So again: I don't see a need for assign_by_ref() or append_by_ref().
> > An assign() allowing both is the best solution.
> Please, tell me, how will you do that without
> call-time-pass-reference?
It's the first time I hear that call_function(&$reference) will be
forbidden in future versions. I don't see a reason for such a step as it
is extremely useful and has no disadvantages (has it???).
So I give you the example again (the 3rd time I think):
<?php
class Smarty
{
var $_tpl_vars = array();
// Simplified assign()
function assign($name, $value)
{
// If assign is called with &$value, $value will be a reference.
// Otherwise ($value or 'A string', new Object(), 0x123, etc.)
// $value will be a copy.
$this->_tpl_vars[$name] = &$value;
// Now we saved the reference into the array. If it's a
// reference to a reference or to a copy - that doesn't matter.
}
}
$smarty = new Smarty();
$smarty->assign('var1', &$reference);
$smarty->assign('var2', $copy);
$smarty->assign('var3', 'a value');
$smarty->assign('var4', new Object());
$smarty->assign('var1', function_return_value());
$smarty->assign('var1', &function_reference_return());
?>
Please correct me if I'm wrong: Why the hell should we discard "call-
time-pass-reference"?
--
Ferdinand Beyer
<fbeyer@clickhand.de>