This is an old revision of the document!
PHP RFC: Apprise on Invalid Arithmetic Operands
- Version: 0.1
- Date: 2016-04-06
- Author: Thomas Punt, firstname.lastname@example.org
- Status: Draft
- First Published at: https://wiki.php.net/rfc/apprise_on_invalid_arithmetic_operands
Following on from the warning about invalid strings in arithmetic RFC, this RFC proposes to warn developers when they are using invalid operands with the arithmetic operators. The overall aim is therefore to help developers catch mistakes in their code when doing something non-sensical.
This is a WIP. Feel free to update this RFC with other cases where you'd like to see
E_NOTICEs emitted (as well as cases of promoting
E_NOTICEs or demoting
This RFC seeks to do the following:
Emit an E_WARNING on resource operands
Reasoning: It is non-sensical behaviour to want to use a resource's ID, particularly without even notifying the programmer (†).
Emit an E_WARNING on null operands
var_dump(1 + null); // currently outputs int(1)
If empty strings (“”) now emit an
E_WARNING, then other non-numeric falsy values should too
Promote the E_NOTICE for object conversions to an E_WARNING
var_dump(1 + new StdClass); // currently outputs int(2) && Notice: Object of class stdClass could not be converted to int...
Reasoning: The coercion is completely non-sensical. It will always coerce an object to int(1) in this context (†), and so the error level should be raised.
(†) Even this, I feel is non-sensical. If other truthy values (such as “abc”) are coerced to int(0), then both objects and resources should too. Right now, objects coerce to int(1), and resource coerces to their resource ID. For now though, this is considered out of the scope of this RFC.
Backward Incompatible Changes
What breaks, and what is the justification for it?
Proposed PHP Version(s)
Describe the impact to CLI, Development web server, embedded PHP etc.
To Existing Extensions
Will existing extensions be affected?
To be done…
If there are any php.ini settings then list:
- hardcoded default values
- php.ini-development values
- php.ini-production values
Make sure there are no open issues when the vote starts!
Unaffected PHP Functionality
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.
This sections details areas where the feature might be improved in future, but that are not currently proposed in this RFC.
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
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.
After the project is implemented, this section should contain
- the version(s) it was merged to
- a link to the git commit(s)
- a link to the PHP manual entry for the feature
Links to external references, discussions or RFCs
Keep this updated with features that were discussed on the mail lists.