PhileCMS / Phile

A flat file CMS with a swappable parser and template engine.
https://philecms.github.io/
Other
257 stars 49 forks source link

PHP 8.2 dynamic properties ErrorException #354

Open iaian7 opened 1 year ago

iaian7 commented 1 year ago

Issue

Dynamic properties are no longer supported in PHP 8.2, and line 46 in /plugins/phile/parserMarkdown/Classes/Parser/Markdown.php causes an ErrorException.

Tested using the latest build in issue #347:

Here's a new build with all the deprecated stuff removed: phile-feature-removeDeprecated-head.zip

Originally posted by @Schlaefer in https://github.com/PhileCMS/Phile/issues/347#issuecomment-1198164583

Quick Fix

Wrapping line 46 with a property check prevents the error, though perhaps masking a more foundational issue (see below).

if (property_exists($parser, $key)) {
    $parser->{$key} = $value;
}

Potential root issue

The configuration appears to be setting a property within the MarkdownExtra class that does not exist, an uncaught issue before PHP 8.2 since dynamically creating properties was previously allowed. Comparing var_dump($this->config); against https://michelf.ca/projects/php-markdown/configuration/ confirms all but "active" are valid properties.

array(16) {
["empty_element_suffix"]=> string(3) " />" 
["tab_width"]=> int(4) 
["no_markup"]=> bool(false) 
["no_entities"]=> bool(false) 
["predef_urls"]=> array(1) { ["base_url"]=> string(16) "http://temp.test" } 
["predef_titles"]=> array(0) { } 
["fn_id_prefix"]=> string(0) "" 
["fn_link_title"]=> string(0) "" 
["fn_backlink_title"]=> string(0) "" 
["fn_link_class"]=> string(12) "footnote-ref" 
["fn_backlink_class"]=> string(16) "footnote-backref" 
["code_class_prefix"]=> string(0) "" 
["code_attr_on_pre"]=> bool(false) 
["predef_abbr"]=> array(0) { } 
["active"]=> bool(true) }

That last "active" property doesn't show up in /plugins/phile/parserMarkdown/config.php so I'm guessing it's from line 104 in /config/defaults.php where the plugin is enabled...shouldn't that be exclusively internal to the Phile plugin, not passed on to the MarkdownExtra class? And if that's the case, how would it be properly corrected? I'm guessing my quick fix above is probably not the right way to do it?