Page MenuHomePhabricator

Fatal error in Parser::extractTagsAndParams static method using $this
Closed, ResolvedPublic

Description

Author: sylvain_machefert

Description:
Hello,

On my wiki (1.12), when I update page using Task extension (which has some hooks on page saving or something like that), I got the error :

Fatal error: Using $this when not in object context in /home/.../includes/Parser.php on line 563

Line 563: (version 1.12)
$marker = "$uniq_prefix-$element-" . sprintf('%08X', $n++) . $this->mMarkerSuffix;

Looking at line 563... it's extractTagsAndParams method which is marked as static. and the line 563 call $this->mMarkerSuffix

Who coded that ? :D


Version: 1.13.x
Severity: critical

Details

Reference
bz13522

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:05 PM
bzimport set Reference to bz13522.
bzimport added a subscriber: Unknown Object (MLST).

robert wrote:

Move private variable mMarkerSuffix to constant MARKER_SUFFIX

This patch converts the private variables $this->mMarkerSuffix to constant self::MARKER_SUFFIX so it can be accessed statically.

attachment markersuffix.patch ignored as obsolete

robert wrote:

Replace all occurances of mMarkerSuffix with MARKER_SUFFIX

Do it to Preprocessor classes as well.

attachment markersuffix2.patch ignored as obsolete

One bad instance of MARK_SUFFIX in the last patch, and the use of single quotes lost the special char and caused some failures. Fixed... now passes parser tests. :D

Applied in r32486

Applied on 1.12 branch in r32487, will be in 1.12.1.

  • Bug 13591 has been marked as a duplicate of this bug. ***

hansen wrote:

Updated patch to preserve the Edit Section Links

After applying the patch for this bug all my edit section links disappeared. If found out that this patch removed some curly braces from the regular expressions. I have fixed this in the uploaded patch.

Attached:

They are not regular expressions but just strings where $this->parser->mMarkerSuffix was replaced by its value. We have to use curly braces to tell PHP that the whole $this->parser->mMarkerSuffix should be replace and not just $this because "-" is not a valid char in variables names.