microsoft / microsoft/tolerant-php-parser

PHP 8.2 would deprecate dynamic properties by default: Consider `#[\AllowDynamicProperties]`

Open
#388 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
894
Forks
85
Avg merge
2d 13h
Merged PRs (30d)
3

Description

NOTE: In my own use case (https://github.com/phan/phan), I use tolerant-php-parser as part of a polyfill that I convert to ast\Node and I end up associating dynamic information with ast\Node instances, so I don't personally need this (they all work fine in php 8.2), but other projects might.
I'm bringing this up so that it can be considered before projects are affected

  • E.g. for caching inferred types, or caching expensive operations such as whether a given node has been processed in a given way, etc

PHP 8.2 deprecates dynamic properties by default and PHP 9.0 will remove support by default without the AllowDynamicProperties annotation. https://wiki.php.net/rfc/deprecate_dynamic_properties

  • Projects using tolerant-php-parser can use WeakMap as a substitute for dynamic properties on Microsoft\PhpParser\Node (though it had worse performance until the latest php minor releases). For php 7.4 and older, https://github.com/TysonAndre/pecl-weakreference_bc is an option I'd created (expecting projects to benefit from this for 8.2 in general) but has low adoption. More conveniently than using a PECL, hybrid approaches such as using dynamic properties/SplObjectStorage in older versions and WeakMaps in newer versions might be possible.

The approaches used in similar libraries:


Options:

  1. Add #[\AllowDynamicProperties] to classes in the current release line, so that php 8.1 and 8.2 will behave the same way, and applications can stay as is

    In 8.x, the memory usage is the same with/without this property

  2. Do nothing, let projects implement alternate solutions when they fix 8.2 deprecations or support 9.0

  3. Add attributes array nodes so that projects can switch to that (increase memory slightly per node by 16 bytes for a zval when empty)


This is out of scope of what I'd prefer in the 0.1.2 release

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the PHP 8.2 dynamic-property deprecation RFC and the approaches cited in nikic/PHP-Parser's lib/PhpParser/Node.php and nikic/php-ast's ast.stub.php. Compare the three options in the issue against tolerant-php-parser's node classes and compatibility targets. Done means one approach is selected, its scope is defined, and the relevant PHP-version behavior is covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.