Re: undefined vars in 'if' statements
| From: | Andrei Zmievski | Date: | Tue, 22 Feb 2000 14:37:10 +0000 |
| Subject: | Re: undefined vars in 'if' statements | ||
| Groups: | php.template | ||
| Request: | Send a blank email to php-template+get-194@lists.php.net to get a copy of this message | ||
On Mon, 21 Feb 2000, Dan Libby wrote:
> Sorry for the delayed responses. been away.
>
> >
> > No, what I mean is this. Say you have:
> >
> > {{ $name default="John" }}
> > ...
> > ...
> > {{ if $name = "Bob" }}
> > ...
> > {{ /if }}
> >
> > If the $name is not assigned a value by the script, then "John" is printed
> > out as the default value. But in the 'if' statement, $name will be
> > undefined so it'll be compared as undefined. Do you see what I'm saying?
>
> Yes, I see. I think that the if statement should only operate on the value
> assigned by the code, if any. One reason is that you could have the same
> variable, $name, used in several places with different defaults for each
> place. I don't really see default acting like an assignment operator.
Ok, that sounds fine to me. If $name is not assigned a value by the
script that it's value will be undefined.
> > >Perhaps the question you are asking is whether the if statement should
> > >behave like a section with regard to autohide, and I think the answer is
> > >yes. It seems like autohide could/should be an attribute of any block
> > >type.
> >
> > You mean, just skip the 'if' statement if it's comparing a variable
> > that's
> > not defined? I'm not sure it's such a good idea...
>
> No, I was referring to what would/should happen if a variable is referenced
> within the if section that was not defined. In that case, I think the if
> statement should have the same behavior as a regular section.
What do you mean by that?
> The if statement should in fact allow testing for whether a variable is
> defined or not.
Is {{ if $name }} enough?
-Andrei
A room without books is like a body without a soul.
-- Marcus Tullius Cicero (106-43 B.C.)