[pmwiki-devel] Testing empty string (was:php logic question)

Patrick R. Michaud pmichaud at pobox.com
Wed Mar 14 07:23:00 CDT 2007


On Wed, Mar 14, 2007 at 10:00:29AM +0100, christian.ridderstrom at gmail.com wrote:
> On Wed, 14 Mar 2007, Jiri Hlad?vka / OBUTEX wrote:
> >I tested an [e]mpty string in PmWiki and found that
> >
> >(:if "" :)
> >and
> >(:if !"" :)
> >
> >are both TRUE
> >
> >(:if equal !"" true:)
> >and
> >(:if equal !"" false:)
> >
> >are both FALSE
> >
> >see http://www.revida.sk/wiki/index.php/Test/8
> 
> That certainly sounds like a bug in PmWiki. 

It's not a bug... or at least, it's working as designed.
The format of the (:if:) conditional is always

     (:if <condname> <params>:)
     (:if ! <condname> <params>:)

and since the "" in (:if "" :) isn't a recognized condition,
PmWiki always treats it as true.

> However, I doubt you can draw any conclusions as to how 
> PHP should behave from this. 

I agree -- it's important to remember that PmWiki conditionals
are different from PHP conditionals.

> But back to the bug... Personally I'd expect a syntax error from
> 
> 	(:if "" :)

In general PmWiki doesn't report "syntax errors", if only because
I'm not sure of a good way to do so.  I suppose I could always
insert text into the markup in such cases.

> (We should look at the user case, i.e. someone doing something like
> 	(:if "{$Variable}" :)
> where {$Variable} is emtpy (or perhaps rather, not set)

If the intent is to test whether $Variable is empty, then the
current markup to do this is:

    (:if equal "{$Variable}" "":)

I don't have any plans to create an (:if "{$Variable}") shortcut,
if only because it's completely irregular to the normal (:if:)
syntax.

Pm




More information about the pmwiki-devel mailing list