[pmwiki-devel] markup() callback fn and $pagename
John Rankin
john.rankin at affinity.co.nz
Mon Feb 24 19:11:57 CST 2014
On 25/02/14 3:05 AM, Petko Yotov wrote:
> V.Krishn writes:
>> I am trying to use a callback as in example here,
>> http://www.pmwiki.org/wiki/PmWiki/CustomMarkup#php55
>> Which of the two conversion methods
>> described here 'PmWiki/CustomMarkup#php55' is recommended
>>
>> in simple replacements code like,
>> "functionName(\$pagename, PSS('$1'))" ?
>
> If your function doesn't use $pagename:
>
> Markup('name', 'where', 'pattern', 'functionName');
> function functionName($m) { } # '$1' is now $m[1], no need for PSS()
Wolfgang pointed out a few days ago that we can also use an anonymous
function:
Markup('name', 'where', 'pattern', function ($m) { return ... ; } );
This requires php 5.3 or later.
>
> If your function uses $pagename, either the above with the extract()
> line, or this:
>
> Markup_e('name', 'where', 'pattern', "functionName(\$pagename,
> \$m[1])");
We can use an anonymous function here too (although I have not tested this):
Markup('name', 'where', 'pattern', function ($m) use (&$pagename) {
return ... ; } );
See http://nz1.php.net/manual/en/functions.anonymous.php
The advantage of Petko's approach is that it works with any version of php.
JR
--
John Rankin
More information about the pmwiki-devel
mailing list