Re: [pmwiki-users] Problem with $FmtPV;
On Tue, May 22, 2007 at 03:34:38PM -0400, Ben Wilson wrote: > On 5/22/07, Vince Admin Account <[EMAIL PROTECTED]> wrote: > >Patrick, please don't end there. Tell us what should be done. > >Is it $x="a2007W19" or ... > >Thanks > > $FmtPV = "'a2007W19'"; # Note, there are single quotes inside the > double quotes. That allows PmWiki to evaluate the string as, er, a > string. Oh, right, yes. I didn't completely understand Vince's comment. If wanting to create a page variable that is a constant string, then use the format Ben just gave (except that $FmtPV needs an index): $FmtPV['$SomeVar'] = "'a2007W19'"; Pm ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users
Re: [pmwiki-users] Problem with $FmtPV;
On Tue, May 22, 2007 at 02:53:42PM -0400, Vince Admin Account wrote: > > On May 22, 2007, at 2:47 PM, Patrick R. Michaud wrote: > > >On Tue, May 22, 2007 at 01:05:08PM -0400, Ben Wilson wrote: > >>On 5/22/07, Patrick R. Michaud <[EMAIL PROTECTED]> wrote: > >>>For example, in PHP I can write: > >>> > >>> $x = a2007W19; > >>> > >>>PHP automaticaly treats the bareword string as though I had written: > >>> > >>> $x = 'a2007W19'; > > > >I should also note that even though PHP _allows_ a programmer > >to write bareword strings in this way, doing so is considered > >very bad (and potentially unsafe) programming practice. > > Patrick, please don't end there. Tell us what should be done. > Is it $x="a2007W19" or ... Oh. In general one should use single quotes instead of bareword strings: $x = a2007W19;# bad $x = 'a2007W19'; # good The same goes for constant string indexes inside of arrays: $a = $x[color]; # bad $a = $x['color']; # good Pm ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users
Re: [pmwiki-users] Problem with $FmtPV;
On 5/22/07, Vince Admin Account <[EMAIL PROTECTED]> wrote: > Patrick, please don't end there. Tell us what should be done. > Is it $x="a2007W19" or ... > Thanks $FmtPV = "'a2007W19'"; # Note, there are single quotes inside the double quotes. That allows PmWiki to evaluate the string as, er, a string. -- Ben Wilson "Words are the only thing which will last forever" Churchill ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users
Re: [pmwiki-users] Problem with $FmtPV;
On May 22, 2007, at 2:47 PM, Patrick R. Michaud wrote: > On Tue, May 22, 2007 at 01:05:08PM -0400, Ben Wilson wrote: >> On 5/22/07, Patrick R. Michaud <[EMAIL PROTECTED]> wrote: >>> >>> In the case where you had >>> >>>$FmtPV['$YearWeek'] = 'a2007W19'; >>> >>> when PHP evaluates "a2007W19" it sees it as a "bareword string" >>> and automatically treats it as a string. For example, in PHP I >>> can write: >>> >>>$x = a2007W19; >>> >>> PHP automaticaly treats the bareword string as though I had written: >>> >>>$x = 'a2007W19'; > > I should also note that even though PHP _allows_ a programmer > to write bareword strings in this way, doing so is considered > very bad (and potentially unsafe) programming practice. > > Pm Patrick, please don't end there. Tell us what should be done. Is it $x="a2007W19" or ... Thanks ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users
Re: [pmwiki-users] Problem with $FmtPV;
On Tue, May 22, 2007 at 01:05:08PM -0400, Ben Wilson wrote: > On 5/22/07, Patrick R. Michaud <[EMAIL PROTECTED]> wrote: > > > >In the case where you had > > > >$FmtPV['$YearWeek'] = 'a2007W19'; > > > >when PHP evaluates "a2007W19" it sees it as a "bareword string" > >and automatically treats it as a string. For example, in PHP I > >can write: > > > >$x = a2007W19; > > > >PHP automaticaly treats the bareword string as though I had written: > > > >$x = 'a2007W19'; I should also note that even though PHP _allows_ a programmer to write bareword strings in this way, doing so is considered very bad (and potentially unsafe) programming practice. Pm ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users
Re: [pmwiki-users] Problem with $FmtPV;
So, the problem is my own misunderstanding of PHP. I appreciate the insight. :-) Regards, Ben On 5/22/07, Patrick R. Michaud <[EMAIL PROTECTED]> wrote: > On Tue, May 22, 2007 at 11:15:33AM -0400, Ben Wilson wrote: > > On 5/22/07, Stirling Westrup <[EMAIL PROTECTED]> wrote: > > > Ben Wilson wrote: > > > > I am setting $FmtPV with the following value: '2007W19'; This is how I > > > > set it, outside of any function, but in a recipe. > > > > > > > > $FmtPV['$YearWeek'] = '2007W19'; > > > > > > This won't work. The contents of $FmtPV are run through eval. That > > > means it has to be a valid PHP expression. 2007W19 isn't one. > > > > Thanks. But then why does it not fail otherwise? > > In the case where you had > > $FmtPV['$YearWeek'] = 'a2007W19'; > > when PHP evaluates "a2007W19" it sees it as a "bareword string" > and automatically treats it as a string. For example, in PHP I > can write: > > $x = a2007W19; > > PHP automaticaly treats the bareword string as though I had written: > > $x = 'a2007W19'; > > But with > > $FmtPV['$YearWeek'] = '2007W19'; > $FmtPV['$YearWeek'] = 'Test-2007W19'; > > PHP ends up evaluating the constants as though we had written > > $x = 2007W19; # $x = 2007 'W19'; > $x = Test-2007W19; # $x = 'Test' - 2007 'W19' > > and gets confused at the W19 part, because it sees a bareword > string where it was expecting an operator of some sort. > > Pm > -- Ben Wilson "Words are the only thing which will last forever" Churchill ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users
Re: [pmwiki-users] Problem with $FmtPV;
On Tue, May 22, 2007 at 11:15:33AM -0400, Ben Wilson wrote: > On 5/22/07, Stirling Westrup <[EMAIL PROTECTED]> wrote: > > Ben Wilson wrote: > > > I am setting $FmtPV with the following value: '2007W19'; This is how I > > > set it, outside of any function, but in a recipe. > > > > > > $FmtPV['$YearWeek'] = '2007W19'; > > > > This won't work. The contents of $FmtPV are run through eval. That > > means it has to be a valid PHP expression. 2007W19 isn't one. > > Thanks. But then why does it not fail otherwise? In the case where you had $FmtPV['$YearWeek'] = 'a2007W19'; when PHP evaluates "a2007W19" it sees it as a "bareword string" and automatically treats it as a string. For example, in PHP I can write: $x = a2007W19; PHP automaticaly treats the bareword string as though I had written: $x = 'a2007W19'; But with $FmtPV['$YearWeek'] = '2007W19'; $FmtPV['$YearWeek'] = 'Test-2007W19'; PHP ends up evaluating the constants as though we had written $x = 2007W19; # $x = 2007 'W19'; $x = Test-2007W19; # $x = 'Test' - 2007 'W19' and gets confused at the W19 part, because it sees a bareword string where it was expecting an operator of some sort. Pm ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users
Re: [pmwiki-users] Problem with $FmtPV;
Thanks. But then why does it not fail otherwise? On 5/22/07, Stirling Westrup <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Ben Wilson wrote: > > I am setting $FmtPV with the following value: '2007W19'; This is how I > > set it, outside of any function, but in a recipe. > > > > $FmtPV['$YearWeek'] = '2007W19'; > > This won't work. The contents of $FmtPV are run through eval. That means it > has to be a valid PHP expression. 2007W19 isn't one. You need to do something > like this: > > $FmtPV['$YearWeek'] = '"2007W19"'; > > Because "2007W19" *is* a valid expression. If you need to use the value of a > (non-global) variable, you'd do it like this: > > > $FmtPV['$YearWeek'] = '"'.$MyVariable.'"'; > > If $MyVariable contains a string with quotes though, things get a bit messier. > > -BEGIN PGP SIGNATURE- > Version: GnuPG v1.4.3 (MingW32) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iD8DBQFGUwT05dZZEoPlyIURAl0pAJ97sphEtX6YXzyg4JWKGrstgGOy4gCeMAZW > 0/MidNKzn/20AA4xzSzTo1M= > =geB3 > -END PGP SIGNATURE- > -- Ben Wilson "Words are the only thing which will last forever" Churchill ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users
Re: [pmwiki-users] Problem with $FmtPV;
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Ben Wilson wrote: > I am setting $FmtPV with the following value: '2007W19'; This is how I > set it, outside of any function, but in a recipe. > > $FmtPV['$YearWeek'] = '2007W19'; This won't work. The contents of $FmtPV are run through eval. That means it has to be a valid PHP expression. 2007W19 isn't one. You need to do something like this: $FmtPV['$YearWeek'] = '"2007W19"'; Because "2007W19" *is* a valid expression. If you need to use the value of a (non-global) variable, you'd do it like this: $FmtPV['$YearWeek'] = '"'.$MyVariable.'"'; If $MyVariable contains a string with quotes though, things get a bit messier. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGUwT05dZZEoPlyIURAl0pAJ97sphEtX6YXzyg4JWKGrstgGOy4gCeMAZW 0/MidNKzn/20AA4xzSzTo1M= =geB3 -END PGP SIGNATURE- ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users