opencaching / opencaching-pl

The source code of Opencaching.PL (and some other domains)
https://opencaching.pl/
GNU General Public License v3.0
22 stars 33 forks source link

Dynamic properties will be deprecated in PHP8.2 #2367

Open deg-pl opened 1 year ago

deg-pl commented 1 year ago

Dynamic class properties will be deprecated in PHP8.2 and will thow an ErrorException in PHP 9. For example below code will throw an error:

class Post
{
    public string $title;
}

// …

$post->name = 'Name';

We use dynamic properties in our code. Main in View and (nearly?) all templates.

But classes implementing get and set will still work as intended:

class Post
{
    private array $properties = [];

    public function __set(string $name, mixed $value): void
    {
        $this->properties[$name] = $value;
    }
}

// …

$post->name = 'Name';

Maybe this is simple/temporary solution?

jrmajor commented 1 year ago

Maybe this is simple/temporary solution?

The easiest solution is to add #[AllowDynamicProperties] attribute, like so:

#[AllowDynamicProperties]
class Post
{
    public string $title;
}