[GH-ISSUE #1651] Monolog version 2.4.0 incompatible with PHP versions <8 #706

Closed
opened 2026-03-04 02:17:15 +03:00 by kerem · 5 comments
Owner

Originally created by @michdingpayc on GitHub (Apr 7, 2022).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1651

The file src/Monolog/Attribute/AsMonologProcessor.php in monolog version 2.4.0 uses constructor property promotion (lines 31-33) which was introduced in PHP version 8.0.

When used in PHP 7.4, one sees the following:
PHP Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in [...]/vendor/monolog/monolog/src/Monolog/Attribute/AsMonologProcessor.php on line 31.

The issue here is the fact that the composer.json file and therefore the monolog/monlog packagist page lists the PHP version requirement as ">=7.2".

Originally created by @michdingpayc on GitHub (Apr 7, 2022). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1651 The file [src/Monolog/Attribute/AsMonologProcessor.php](https://github.com/Seldaek/monolog/blob/2.4.0/src/Monolog/Attribute/AsMonologProcessor.php) in monolog version 2.4.0 uses constructor property promotion (lines 31-33) which was introduced in PHP version 8.0. When used in PHP 7.4, one sees the following: `PHP Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in [...]/vendor/monolog/monolog/src/Monolog/Attribute/AsMonologProcessor.php on line 31`. The issue here is the fact that the[ composer.json file](https://github.com/Seldaek/monolog/blob/2.4.0/composer.json) and therefore the [monolog/monlog packagist page](https://packagist.org/packages/monolog/monolog#2.4.0) lists the PHP version requirement as `">=7.2"`.
kerem 2026-03-04 02:17:15 +03:00
  • closed this issue
  • added the
    Bug
    label
Author
Owner

@Seldaek commented on GitHub (Apr 7, 2022):

Attributes are a php8 feature so you cannot use this class on 7.4 anyway and I'm not sure what you are doing?

<!-- gh-comment-id:1092298938 --> @Seldaek commented on GitHub (Apr 7, 2022): Attributes are a php8 feature so you cannot use this class on 7.4 anyway and I'm not sure what you are doing?
Author
Owner

@wp-seopress commented on GitHub (Apr 8, 2022):

Same issue here, VS Code returns an error.

Solution?

public function __construct(?string $channel = null, ?string $handler = null, ?string $method = null) {

<!-- gh-comment-id:1092698248 --> @wp-seopress commented on GitHub (Apr 8, 2022): Same issue here, VS Code returns an error. Solution? `public function __construct(?string $channel = null, ?string $handler = null, ?string $method = null) {`
Author
Owner

@michdingpayc commented on GitHub (Apr 8, 2022):

Attributes are a php8 feature so you cannot use this class on 7.4 anyway and I'm not sure what you are doing?

Thank you for the quick response.

The attribute class isn't used in the PHP 7.4 project I'm referencing, but the monolog vendor directory is preloaded into opcache. This is done for performance purposes but with monolog version 2.4.0 that is also where this issue arises.

The file can be explicitly excluded from preloading, but I would like to hear your thoughts first.

<!-- gh-comment-id:1092858568 --> @michdingpayc commented on GitHub (Apr 8, 2022): > Attributes are a php8 feature so you cannot use this class on 7.4 anyway and I'm not sure what you are doing? Thank you for the quick response. The attribute class isn't used in the PHP 7.4 project I'm referencing, but the monolog vendor directory is preloaded into opcache. This is done for performance purposes but with monolog version 2.4.0 that is also where this issue arises. The file can be explicitly excluded from preloading, but I would like to hear your thoughts first.
Author
Owner

@Seldaek commented on GitHub (Apr 8, 2022):

Fixed in github.com/Seldaek/monolog@508df120fa - please upgrade to 2.5.0

<!-- gh-comment-id:1093021591 --> @Seldaek commented on GitHub (Apr 8, 2022): Fixed in https://github.com/Seldaek/monolog/commit/508df120fac348c1e7ed6e590d83c549fa95434e - please upgrade to 2.5.0
Author
Owner

@michdingpayc commented on GitHub (Apr 8, 2022):

Thank you kindly!

<!-- gh-comment-id:1093093211 --> @michdingpayc commented on GitHub (Apr 8, 2022): Thank you kindly!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#706
No description provided.