Scout APM helps PHP developers pinpoint N+1 queries, memory leaks & more so you can troubleshoot fast & get back to coding faster. Deprecations often are a source of frustration, though it's important to realise they are actually very helpful.

For example this Post class doesn't have a name property, but nevertheless we set it at runtime: class Post { } $post = new Post(); $post->name = 'Name'; var_dump($post->name); As of PHP 8.2, these dynamic properties will be deprecated: $post->name = 'Name'; You'll see this message: Deprecated: Creation of dynamic property Post::$name is deprecated.

Classes that implement these magic functions will keep working as intended: class Post { private array $properties = []; public function __set(string $name, mixed $value): void { $this->properties[$name] = $value; }} $post->name = 'Name'; The same goes for objects of stdClass, they will support dynamic properties just as before: $object = new stdClass(); $object->name = 'Name'; Now some clever readers might wonder: if stdClass still allows dynamic properties, what would happen if you'd extend from it?

The PHP core team has provided a built-in https://stitcher.io/blog/attributes-in-php-8 called AllowDynamicProperties.As its name suggests, it allows dynamic properties on classes, without having to rely on sketchy extends: class Post { } $post = new Post(); $post->name = 'Name'; #closing-thoughts Closing thoughts
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners