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_WARNING
s or E_NOTICE
s emitted (as well as cases of promoting E_NOTICE
s or demoting E_WARNING
s).
EDIT related: https://bugs.php.net/bug.php?id=67904
This RFC seeks to do the following:
var_dump(1 + fopen(__FILE__, 'r')); // currently outputs int(6)
Reasoning: It is non-sensical behaviour to want to use a resource's ID, particularly without even notifying the programmer (†).
var_dump(1 + null); // currently outputs int(1)
Reasoning:
If empty strings (“”) now emit an E_WARNING
, then other non-numeric falsy values should too
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.
What breaks, and what is the justification for it?
PHP 7.1
Describe the impact to CLI, Development web server, embedded PHP etc.
Will existing extensions be affected?
To be done...
None.
If there are any php.ini settings then list:
Make sure there are no open issues when the vote starts!
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.
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)
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
Links to external references, discussions or RFCs
Keep this updated with features that were discussed on the mail lists.