Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHP 8.2] - Deprecated: Creation of dynamic... for links in messages #9562

Closed
rich20 opened this issue Sep 17, 2023 · 19 comments
Closed

[PHP 8.2] - Deprecated: Creation of dynamic... for links in messages #9562

rich20 opened this issue Sep 17, 2023 · 19 comments
Milestone

Comments

@rich20
Copy link
Member

rich20 commented Sep 17, 2023

To Reproduce
Include simple links in a message, e.g.
https://www.kunena.org/
or
[url]https://www.kunena.org/[/url]

Actual result

Deprecated: Creation of dynamic property Kunena\Forum\Libraries\Layout\KunenaLayout::$url is deprecated in /.../libraries/kunena/src/Layout/KunenaBase.php on line 570

System information

  • Joomla version: ‎4.4.0-beta2-dev
  • Joomla template: CASSIOPEIA
  • Kunena version: 6.2-0-beta2
  • Kunena template: Aurelia
  • Php version: 8.2.9
  • Database version: 10.5.21-MariaDB

Desktop

  • OS: Ubuntu 22.04.1 LTS
  • Browser: Chromium, Firefox and Opera
@rich20 rich20 added this to the 6.2 milestone Sep 17, 2023
@xillibit
Copy link
Member

I'am not able to reproduce this one on Php 8.2.x

@rich20
Copy link
Member Author

rich20 commented Sep 18, 2023

I have tried it on 3 different test sites with php 8.2.4 and php 8.2.9.
This message is displayed on migrated or updated pages as well as on newly installed Kunena.

@xillibit
Copy link
Member

Can-you add here the backtrace like that i can see where it's come ?

@rich20
Copy link
Member Author

rich20 commented Sep 19, 2023

Backtracking is hardly possible. But I noticed that this message, along with the many "deprecated" codes, is already displayed in Kunena 6.1.
It is interesting that if Auto-Link URLs is disabled in the configuration, these messages also disappear for links that were inserted with [url] [/url].

@xillibit
Copy link
Member

I have tried by enabling Auto-Link URLs but the error hasn't appear

@rich20
Copy link
Member Author

rich20 commented Sep 20, 2023

Well, let's leave the issue aside for now. If the error is there, it can only be seen anyway if the error reporting is at maximum.

@810
Copy link
Member

810 commented Sep 20, 2023

i can't see the error also

@rich20
Copy link
Member Author

rich20 commented Sep 20, 2023

Maybe this will help. I had overlooked the fact that three different warnings are displayed per link.

Deprecated: Creation of dynamic property Kunena\Forum\Libraries\Layout\KunenaLayout::$url is deprecated in .../libraries/kunena/src/Layout/KunenaBase.php on line 570

Deprecated: Creation of dynamic property Kunena\Forum\Libraries\Layout\KunenaLayout::$target is deprecated in .../libraries/kunena/src/Layout/KunenaBase.php on line 570

Deprecated: Creation of dynamic property Kunena\Forum\Libraries\Layout\KunenaLayout::$internal is deprecated in ..../libraries/kunena/src/Layout/KunenaBase.php on line 570

@xillibit
Copy link
Member

xillibit commented Oct 9, 2023

Backtracking is hardly possible.

Why ? If you xdebug enabled it shows directly the backend for each error displayed or else if you look in the log of php there are the backtrace for each error message

@rich20
Copy link
Member Author

rich20 commented Oct 16, 2023

Fixed with this: 5dd4a03

@rich20 rich20 closed this as completed Oct 16, 2023
@rich20
Copy link
Member Author

rich20 commented Oct 16, 2023

Sorry, it was a mistake from me. The deprecated codes are still present.

@rich20 rich20 reopened this Oct 16, 2023
@Ruud68
Copy link
Contributor

Ruud68 commented Oct 20, 2023

Hi,
this issue is in multiple views. The issue here is that this function in KunenaBase.php is invoked:

    /**
     * Modifies a property of the object, creating it if it does not already exist.
     *
     * @param   string  $key    The name of the property.
     * @param   mixed   $value  The value of the property to set.
     *
     * @return  \Kunena\Forum\Libraries\Layout\KunenaBase
     *
     * @since   Kunena 6.0
     */
    public function set($key, $value)
    {
        $isFactory = \is_object($value) && method_exists($value, '__invoke');

        if ($isFactory) {
            $this->closures[$key] = $value;
        } else {
            $this->{$key} = $value;
        }

        return $this;
    }

with $this->{$key} you are setting keys that are not declared in KunenaBase.php. It still works but doing this is deprecated in PHP 8.2 and will stop working in newer PHP versions.

So setting variables to an object must be refactored into another way of doing this.

an approach would be to define a private array $data variable and the use $this->data[$key] = $value to set data in it. We then also net a get function that will then return the $data[$key] value.

No idea what the impact of this change would be as now it is possible to directly get a variable from the object where then it is only possible to use the get function to get the variable

@xillibit
Copy link
Member

xillibit commented Oct 20, 2023

I know, I have already corrected a lot in K6.2 of this deprecated, i have started a bit in K6.1. I have created the layout file if it's not exist to define variables. From the deprecated messages reported by rich, this i'am not able to see it :

Deprecated: Creation of dynamic property Kunena\Forum\Libraries\Layout\KunenaLayout::$url is deprecated in .../libraries/kunena/src/Layout/KunenaBase.php on line 570

Deprecated: Creation of dynamic property Kunena\Forum\Libraries\Layout\KunenaLayout::$target is deprecated in .../libraries/kunena/src/Layout/KunenaBase.php on line 570

Deprecated: Creation of dynamic property Kunena\Forum\Libraries\Layout\KunenaLayout::$internal is deprecated in ..../libraries/kunena/src/Layout/KunenaBase.php on line 570

@Ruud68
Copy link
Contributor

Ruud68 commented Oct 20, 2023

You can do a grep "\$this->internal" . -R | grep kunena -i in your site directory.
That will list all used instances, same for $this->url, $this->target, etc.

e.g. for $this->internal I found the following:
components/com_kunena/template/aurelia/layouts/bbcode/url/default.php:if (!$this->internal) {

@Ruud68
Copy link
Contributor

Ruud68 commented Oct 20, 2023

fixed mine: #9570

@Ruud68
Copy link
Contributor

Ruud68 commented Oct 20, 2023

and was able to reproduce the $url, $target and $internal so also fixed these in same PR

@rich20
Copy link
Member Author

rich20 commented Oct 20, 2023

  • Success! With your fix all error are gone.

@Ruud68
Copy link
Contributor

Ruud68 commented Oct 20, 2023

Thanks for testing @rich20

@rich20
Copy link
Member Author

rich20 commented Oct 24, 2023

Already solved by this fix #9570

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants