Reason for using a class (was Re: [Pmwiki-users] Re: Request for)

Patrick R. Michaud pmichaud
Fri Jul 23 14:12:51 CDT 2004


On Fri, Jul 23, 2004 at 12:40:09PM -0700, Ben Shakal wrote:
> Hi Patrick, I just had a quick question...  I admit I haven't studied
> pmwiki's internals in too much detail, but I know PHP well, and I'm
> not sure I understand why using arrays or classes prevents variables
> from being used in the $...Fmt strings.  Is this something specific to
> the way pmwiki builds those strings?  Shouldn't
> "...{$MailPosts['To']}..."  or "...$MailPosts[To]..." work?

At present PmWiki does its own string interpolation via the FmtPageName()
function, for several reasons:
  1.  Some substitutions are not simple--they have to be dynamically
      determined based on factors at the time of substitution--e.g.,
      $ScriptUrl/$Group/$Title_ in a $...Fmt string has to be
      converted to $ScriptUrl?pagename=$Group.$Title if $EnablePathInfo==0.
  2.  Some substitutions have to occur in a specific sequence; e.g.,
      $...Fmt strings and $[i18n] translations take place before other
      substitutions.
  3.  AFAICT, it's difficult to get PHP's built-in string interpolator 
      to use variables from the global scope from within a subroutine.
      And I certainly don't trust eval() on arbitrary strings.
  4.  Even if you can get PHP's interpolator to use globally scoped
      variables, there are some "unsafe" variables that probably shouldn't
      be substituted for security/privacy reasons.

FmtPageName gets called a lot--probably more than any other function.
For several reasons, especially efficiency, I decided that substitutions
of array and class values added far more overhead than it was worth.

> Also, I've been lurking on the mailing list for a while now, and I
> want to thank you for being so responsive and helpful... 

You're welcome--I really enjoy it.

> I hope it is not just a matter of time before newbies get 
> annoying to you! :)

Not at all, in many ways "newbies" are my target audience.  :-)

Pm



More information about the pmwiki-users mailing list