[dokuwiki] Re: Multiple parser instances and PARSER_WIKITEXT_PREPROCESS

  • From: Christopher Smith <chris@xxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Wed, 29 Dec 2010 12:11:20 +0000

On 28 Dec 2010, at 23:41, TNHarris wrote:

> On 12/26/2010 06:35 PM, Michael Hamann wrote:
>> 
>> I think the problem is that p_get_parsermodes() uses a static array to
>> cache the modes. Thus you get the exactly same mode objects as
>> p_get_instructions gets. $parser->addMode() now sets the "Lexer"
>> attribute of each mode which is probably what causes these problems.
>> Some print_r() statements have confirmed my assumptions, the problem is
>> that PHP returns objects by reference so we have the same mode objects
>> in all parsers but different lexer objects.
>> 
> 
> Thanks for looking into this.
> 
> Okay, I see it now. Would it be solved by removing the explicit reference 
> operators from $Mode in Doku_Parser::addMode? PHP objects are normally 
> copy-on-write (I think), so setting the Lexer reference will copy each mode 
> object for that instance of the parser (maybe?).
> 

No, since PHP5, objects are always passed by reference, the '&' operator is 
redundant and the 'clone' keyword is required to copy an object.  As DokuWiki 
now requires PHP5, the code should probably be updated to remove them.

I can't think of any specific reason why the call to PARSER_WIKITEXT_PREPROCESS 
event is in that particular place (I think it was me that placed it there).  If 
there are advantages to moving it before instantiation of the parser and its 
not likely to break anything (I don't think it will), I don't see why it can't 
be moved.

- Chris

Other related posts: