Skip to content

[4.2] PHP8.2 Allow dynamic properties in Log class#39599

Merged
HLeithner merged 2 commits intojoomla:4.2-devfrom
Digital-Peak:php82/log
Jan 12, 2023
Merged

[4.2] PHP8.2 Allow dynamic properties in Log class#39599
HLeithner merged 2 commits intojoomla:4.2-devfrom
Digital-Peak:php82/log

Conversation

@laoneo
Copy link
Copy Markdown
Member

@laoneo laoneo commented Jan 11, 2023

Summary of Changes

Allows dynamic properties on log entries so different formatters can add custom properties.

Testing Instructions

Open the article form on the PHP 8.2 on the front end with debug enabled.

Actual result BEFORE applying this Pull Request

The following warning is shown:
Creation of dynamic property Joomla\CMS\Log\LogEntry::$clientIP is deprecated

Expected result AFTER applying this Pull Request

No warning.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@alikon
Copy link
Copy Markdown
Contributor

alikon commented Jan 11, 2023

I have tested this item ✅ successfully on 1c8a2c3

code review


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39599.

@laoneo laoneo added the PHP 8.x PHP 8.x deprecated issues label Jan 11, 2023
@joomdonation
Copy link
Copy Markdown
Contributor

Shouldn't we add the missing properties instead? By scanning the code, there are two missing properties:

@alikon
Copy link
Copy Markdown
Contributor

alikon commented Jan 11, 2023

should be enough based on https://php.watch/versions/8.2/AllowDynamicProperties

@laoneo
Copy link
Copy Markdown
Member Author

laoneo commented Jan 11, 2023

First I did this, then I came to the conclusion that, every formater can add it's own custom properties. That's why I made it that way. The text logger is a good example. It adds specific properties which are only used by that specific logger. Others can do the same. That's why the LogClass should allow dynamic properties.

@joomdonation
Copy link
Copy Markdown
Contributor

should be enough based on https://php.watch/versions/8.2/AllowDynamicProperties

Enough for not but will result on fatal error on PHP 9. I think we should take this chance to fix the code properly instead of hiding the warnings for now and suddenly seeing fatal when PHP 9 releases.

@joomdonation
Copy link
Copy Markdown
Contributor

then I came to the conclusion that, every formatter can add it's own custom properties

Hard to discuss without seeing the real code. If we really have to allow define dynamic property like that, maybe make the class LogEntry extends \stdClass could be an option. I will leave this to someone else to decide.

@laoneo
Copy link
Copy Markdown
Member Author

laoneo commented Jan 11, 2023

The AllowDynamicProperties attribute should also work in PHP 9. There is no indication in the RFC, that this attribute will not work.

@joomdonation
Copy link
Copy Markdown
Contributor

Base on various sources I read , it will be fatal error on PHP 9:

The deprecation notice is emitted on PHP 8.2 and later. In PHP 9.0, dynamic properties will result in a fatal error.

And remember that it won't be a fatal error until PHP 9.0, so there's plenty of time to deal with it

That's reason I want to add missing properties when it's possible instead of using AllowDynamicProperties

@laoneo
Copy link
Copy Markdown
Member Author

laoneo commented Jan 11, 2023

It will be a fatal error only when the AllowDynamicProperties attribute is not there.

@joomdonation
Copy link
Copy Markdown
Contributor

It will be a fatal error only when the AllowDynamicProperties attribute is not there

Ah, OK. Read the RFC again, I can confirm that. Thanks !

@carlitorweb
Copy link
Copy Markdown
Member

I like the approch of make the class LogEntry extends \stdClass. In my opinion this is a more stable solution than add the attribute

@carlitorweb
Copy link
Copy Markdown
Member

I have tested this item ✅ successfully on 1c8a2c3


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39599.

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 12, 2023

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39599.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jan 12, 2023
@HLeithner HLeithner merged commit f67504f into joomla:4.2-dev Jan 12, 2023
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jan 12, 2023
@HLeithner
Copy link
Copy Markdown
Member

I think that's a bad idea and we should find a better way but for now it's ok.
thanks

@laoneo laoneo deleted the php82/log branch January 12, 2023 16:19
@Quy Quy added this to the Joomla! 4.2.7 milestone Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PHP 8.x PHP 8.x deprecated issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants