Page MenuHomePhorge

Fix "Creation of dynamic property is deprecated" PHP 8.2 error in MimeMailParser
ClosedPublic

Authored by aklapper on Mar 29 2024, 11:36.
Tags
None
Referenced Files
Unknown Object (File)
Thu, May 2, 07:56
Unknown Object (File)
Tue, Apr 30, 06:30
Unknown Object (File)
Tue, Apr 30, 04:48
Unknown Object (File)
Tue, Apr 30, 04:46
Unknown Object (File)
Fri, Apr 26, 20:10
Unknown Object (File)
Fri, Apr 26, 20:10
Unknown Object (File)
Fri, Apr 26, 20:10
Unknown Object (File)
Fri, Apr 26, 20:10

Details

Summary

Add #[AllowDynamicProperties] attribute to avoid the deprecation notice.

See https://php.watch/versions/8.2/dynamic-properties-deprecated

# ERROR 8192: Creation of dynamic property MimeMailParser::$parts is deprecated at [/var/www/html/phorge/phorge/externals/mimemailparser/MimeMailParser.class.php:137]
#  #0 MimeMailParser::parse() called at [<phorge>/externals/mimemailparser/MimeMailParser.class.php:126]

Closes T15765

Test Plan

See T15765

Diff Detail

Repository
rP Phorge
Branch
arcpatch-D25563
Lint
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 1131
Build 1131: arc lint + arc unit

Event Timeline

Can we just define the used properties instead? Doesn't look like there's too many of them.

I agree and I'm quite sure that just parts is missing

externals/mimemailparser/MimeMailParser.class.php
438

Unrelated but this legacy part is weird. Maybe:

$encoding = array_key_exists('content-transfer-encoding', $part['headers'])
  ? $part['headers']['content-transfer-encoding']
  : '';
489

Unrelated but we may want to remove this ending ?> since it's good practice to avoid that if we have not output after that.

Plenty of creative scope for a follow-up Diff - T15766

externals/mimemailparser/MimeMailParser.class.php
92

Unrelated but this return is never reached 🤔

120

Unrelated but this is not indented correctly ↑

Can we just define the used properties instead? Doesn't look like there's too many of them.

Is that really as trivial as in my last revision? Sorry, still considering myself a PHP newbie, plus this codebase seems to be quite bitrotting.

FYI:

  • For debugging, at the end of function parse() in MimeMailParser.class.php I added phlog(pht(json_encode(mailparse_msg_get_part_data($part))));.
  • While playing with the code I did sometimes get an unexpectedly empty "headers":[] in the $part, leading later to (RuntimeException) Undefined index: subject, but failed to properly reproduce so far.

and now for real, without #[\AllowDynamicProperties]

Is that really as trivial as in my last revision?

Yeah, pretty much.

externals/mimemailparser/MimeMailParser.class.php
38

we don't like [] for array initialization - use array().

137

Maybe keep this, just to make sure we don't leak anything across executions

Correct array initialization; keep line in parse().

Tested again locally; still works as expected for this very task.

This revision is now accepted and ready to land.Mar 31 2024, 12:17

(Whops! wrong summary)

externals/mimemailparser/MimeMailParser.class.php
464

Unrelated but unreachable return