rfc:mixed_vs_untyped_properties

This is an old revision of the document!


PHP RFC: Your Title Here

Introduction

This RFC proposes to remove the distinction between “typed” and “untyped” properties, by treating any property with no type information as though it was declared mixed. This is primarily aimed to reduce confusion around different states, error messages, and behaviours; to do so, it makes the language stricter in some circumstances.

PHP currently has three primary ways of adding properties to an object:

  1. Dynamically. The property is created automatically on a specific instance when it is first assigned to, and can be deleted completely using unset.
  2. Declared, with optional visibility. The property is part of the class definition, and allocated on every instance, even if it is never assigned. The behaviour of unset is complex, hiding but not fully deleting the property.
  3. Declared with a type. In addition to being allocated on every instance, the property is covered by extra guards on assignment to guarantee its type. If it is never assigned a value, or passed to unset, it is assigned a special “uninitialized” state.

The different behaviours of these properties are largely a result of the history of the language, rather than a consistent design. In particular, with the addition of the ''mixed'' type, it would seem logical for private $foo; to be short-hand for private mixed $foo;, since no type-guards are needed; but this is not currently the case, due to the different handling of initial states and unset.

Proposal

Backward Incompatible Changes

Un-typed properties will no longer have an implicit initial value of null.

Proposed PHP Version(s)

'TODO' List the proposed PHP versions that the feature will be included in. Use relative versions such as “next PHP 8.x” or “next PHP 8.x.y”.

RFC Impact

To SAPIs

'TODO' Describe the impact to CLI, Development web server, embedded PHP etc.

To Existing Extensions

'TODO' Will existing extensions be affected?

To Opcache

'TODO' It is necessary to develop RFC's with opcache in mind, since opcache is a core extension distributed with PHP.

Please explain how you have verified your RFC's compatibility with opcache.

Open Issues

'TODO' Make sure there are no open issues when the vote starts!

Unaffected PHP Functionality

'TODO' List existing areas/features of PHP that will not be changed by the RFC.

This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise.

Future Scope

'TODO' This section details areas where the feature might be improved in future, but that are not currently proposed in this RFC.

Proposed Voting Choices

'TODO' Include these so readers know where you are heading and can discuss the proposed voting options.

Patches and Tests

Links to any external patches and tests go here.

If there is no patch, make it clear who will create a patch, or whether a volunteer to help with implementation is needed.

Make it clear if the patch is intended to be the final patch, or is just a prototype.

For changes affecting the core language, you should also provide a patch for the language specification.

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged into
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature
  4. a link to the language specification section (if any)

References

Rejected Features

Keep this updated with features that were discussed on the mail lists.

rfc/mixed_vs_untyped_properties.1700142423.txt.gz · Last modified: 2023/11/16 13:47 by imsop