> John Rankin writes: >> >> > http://www.pmwiki.org/wiki/PmWiki/CustomMarkup#php55 >> >> In a lot of cases, I'm going to need the 'use' keyword to pass >> parameters to the callback function. > > This will not work for PHP versions 5.2 and older IIRC, and you cannot > declare inline (native) lambda functions (closures) before PHP 5.3. That's > why in MarkupToHTML() I export a global array with the $pagename local > variable and extract() it in the callback functions. If there is a better > way, that is compatible with new and old PHP versions, I'll gladly review > it and use it.
Professor Google suggested this alternative, using object-method callback: class Callback { public $parameter; public function handle($matches) { return $matches[1] . ($matches[2] + $this->parameter); } } $instance = new Callback(); $instance->parameter = 99; echo preg_replace_callback("|(\d{2}/\d{2}/)(\d{4})|", array($instance, 'handle'), $text); Any advice on whether I should use global variables or the object-method to pass variables to the callback function? The code I'm looking at uses preg_replace with /e a lot, and I'm a little reluctant to use global variables to pass parameters. TIA JR -- John Rankin _______________________________________________ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users