Table of Contents

PHP RFC: Introduce Type Affinity

Introduction

PHP is weakly typed to make it work with Web smoothly. However, precise data type usage is more an more important in these days. Weakly typed does not mean typeless. SQLite2 was typeless, but SQLite3 became type aware by “Type Affinity” to achieve better performance.

https://www.sqlite.org/datatype3.html

SQLite3 stores data as native data type if input for the field is appropriate for field data type.

PHP may have type affinity for both better performance and code.

Since inputs are converted to native type.

Proposal

Introduce SQLite3 like type affinity for $_GET/$_POST/$_COOKIE/$_FILES/$_ENV/$_SERVER:

There are few possible ways.

Introduce type affinity conversion function:

Type affinity may be applied to any inputs including databases/$argv/etc.

Please suggest other ways/ideas. Thank you.

Backward Incompatible Changes

Inputs (e.g. $_GET/etc) has string data typed always currently. Type affinity introduce native type for inputs.

Proposed PHP Version(s)

PHP 7.x

RFC Impact

To SAPIs

None.

To Existing Extensions

None.

To Opcache

None.

New Constants

None.

php.ini Defaults

If there are any php.ini settings then list:

Open Issues

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

Unaffected PHP Functionality

Future Scope

Type affinity can increase usefulness of strict data typing.

Proposed Voting Choices

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

State whether this project requires a 2/3 or 50%+1 majority (see voting)

Patches and Tests

TBD

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged to
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature

References

Links to external references, discussions or RFCs

Rejected Features

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