rfc:empty_function

This is an old revision of the document!


PHP RFC: Your Title Here

Introduction

So far the goal of the standard function `empty' is, according to the official documentation, to “determine whether a variable is empty”. There are kinds of flaws that should be settled, in my viewpoint:

1) the semantics: the function name is ambiguous about the action, that is, it is not clear whether the goal of empty() function should consist of testing the `emptiness' of input variable or return an empty version of the input variable.

2) the behavior. The only two issues come from inputing no variable or managing the false/true constant values. We resume it all throughout the code below:

echo “built-in function `empty'<br/>”; echo “null value: ”.( empty( null ) ? “Yes” : “No” ).“<br/>”; echo “undeclared var : ”.( empty( $i ) ? “Yes” : “No” ).“<br/>”; echo “empty input : ”.( empty() ? “Yes” : “No” ).“<br/>”; empty input var will let code crash echo “empty string : ”.( empty( “” ) ? “Yes” : “No” ).“<br/>”; echo “empty array : ”.( empty( [] ) ? “Yes” : “No” ).“<br/>”; $i = 1; echo “boolean false : ”.( empty( false ) ? “Yes” : “No” ).“<br/>”; expected return value : 1 echo “boolean true : ”.( empty( true ) ? “Yes” : “No” ).“<br/>”; expected return value : 1 echo “declared var : ”.( empty( $i ) ? “Yes” : “No” ).“<br/>”; expected return value : 1 echo “non-empty string : ”.( empty( “something” ) ? “Yes” : “No” ).“<br/>”; expected return value : 1 echo “non empty array : ”.( empty( [10] ) ? “Yes” : “No” ).“<br/>”; expected return value : 1 ===== Proposal ===== All the features and examples of the proposal. To paraphrase Zeev Suraski, explain hows the proposal brings substantial value to be considered for inclusion in one of the world's most popular programming languages. Remember that the RFC contents should be easily reusable in the PHP Documentation. If applicable, you may wish to use the language specification as a reference. ===== Backward Incompatible Changes ===== What breaks, and what is the justification for it? ===== Proposed PHP Version(s) ===== 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 ==== Describe the impact to CLI, Development web server, embedded PHP etc. ==== To Existing Extensions ==== Will existing extensions be affected? ==== To Opcache ==== 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. ==== New Constants ==== Describe any new constants so they can be accurately and comprehensively explained in the PHP documentation. ==== php.ini Defaults ==== If there are any php.ini settings then list: * hardcoded default values * php.ini-development values * php.ini-production values ===== Open Issues ===== 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. ===== Future Scope ===== This section 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. ===== 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 - the version(s) it was merged into - a link to the git commit(s) - a link to the PHP manual entry for the feature - a link to the language specification section (if any) ===== References ===== Links to external references, discussions or RFCs ===== Rejected Features ===== Keep this updated with features that were discussed on the mail lists.

rfc/empty_function.1698666919.txt.gz · Last modified: 2023/10/30 11:55 by alessandro.a.rosa_gmail.com