rfc:empty_function
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:empty_function [2023/10/30 11:56] – created alessandro.a.rosa_gmail.com | rfc:empty_function [2023/10/31 16:42] (current) – Under Discussion alessandro.a.rosa_gmail.com | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Your Title Here ====== | + | ====== PHP RFC: standard built-in is_empty() function |
- | * Version: 0.1 | + | * Version: 0.2 |
- | * Date: 2023-10-30 | + | * Date: 2023-10-31 |
* Author: Alessandro Rosa, alessandro.a.rosa@gmail.com | * Author: Alessandro Rosa, alessandro.a.rosa@gmail.com | ||
* Status: Under Discussion | * Status: Under Discussion | ||
Line 7: | Line 7: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | So far the goal of the standard | + | The official documentation |
- | 1) the semantics: | + | Here the purpose of the function |
- | 2) the behavior. The only two issues come from inputing no variable | + | Defining `emptiness' |
+ | > Merriam-Webster: | ||
+ | I do not like the usage of the above term `nothing', | ||
+ | |||
+ | In this sense, a little better version follows: | ||
+ | > Oxford dictionary: `//The condition of being without contents//' | ||
+ | |||
+ | But it can be improved further in terms of specialized contents for containers, being actually the habitat of variables in programming languages. Finally, a more refined definition is the next, because it sets up a quality relation in terms of `appropriate' | ||
+ | > Dictionary.com: | ||
+ | |||
+ | Before our conclusions, | ||
+ | |||
+ | <PHP> | ||
+ | //a container for storing an integer number was instantiated, | ||
+ | //named `integer' | ||
+ | $integer = 1; | ||
+ | |||
+ | //In C-family languages, it will ruled through this instantiation | ||
+ | //int < | ||
+ | </ | ||
+ | |||
+ | Emptiness here occurs __only__ when | ||
+ | < | ||
+ | is coded. | ||
+ | |||
+ | <PHP> | ||
+ | //a container for storing an integer number was instantiated, | ||
+ | //named `float' | ||
+ | $float = 1.1; | ||
+ | |||
+ | //In C-family languages, it will ruled through this instantiation | ||
+ | //double < | ||
+ | </ | ||
+ | |||
+ | Analogously, | ||
+ | < | ||
+ | is coded. A slightly variegated situation occurs for emptiness of strings: | ||
+ | |||
+ | <PHP> | ||
+ | //a container for storing a sequence of characters was instantiated | ||
+ | //named `string' | ||
+ | $string = "< | ||
+ | |||
+ | //In C-family languages, it corresponds to the pointer-like syntax | ||
+ | //char* < | ||
+ | </ | ||
+ | |||
+ | Emptiness here occurs in two cases: when | ||
+ | < | ||
+ | or | ||
+ | < | ||
+ | are coded. | ||
+ | |||
+ | We conclude that the definition of `emptiness' | ||
+ | `//Returns true if var does not exist or has a value that is empty or equal to zero, aka falsey, see conversion to boolean. Otherwise returns false//' | ||
+ | |||
+ | In my viewpoint, the optimal behavior of any emptiness-test function shall rely upon the match between the container and the kind of contents. I resumed here below the flaws that should be eventually settled: | ||
+ | |||
+ | 1) the **semantics**: | ||
+ | |||
+ | 2) the **behavior**. The only three issues arise from inputing no variable or managing the false and 0 constant values. | ||
+ | |||
+ | The ordinary behavior with all the built-in datatypes has been listed below: | ||
+ | |||
+ | <PHP> | ||
+ | echo " | ||
+ | echo "Stage 1: empty, undeclared or null containers (`empty' | ||
+ | echo "null value >> empty( null ): ".( empty( null ) ? " | ||
+ | echo " | ||
+ | //echo "empty input >> empty() : ".( empty() ? " | ||
+ | echo "empty string >> empty( \" | ||
+ | echo "empty array >> empty( [] ) : ".( empty( [] ) ? " | ||
+ | |||
+ | $res = fopen( ' | ||
+ | echo " | ||
+ | echo " | ||
+ | if ( $res !== false ) fclose( $res ); | ||
+ | |||
+ | echo "Stage 2: non-empty containers (`empty' | ||
+ | echo " | ||
+ | echo " | ||
+ | echo " | ||
+ | |||
+ | $a; | ||
+ | echo " | ||
+ | |||
+ | $i = 1; // I have declared a variable for the test below | ||
+ | echo " | ||
+ | |||
+ | echo " | ||
+ | echo "non empty array >> empty( [10] ) : ".( empty( [10] ) ? " | ||
+ | </ | ||
+ | |||
+ | We remark, to the benefit of readers, that the empty string is namely ''""'', | ||
+ | |||
+ | < | ||
+ | |||
+ | or | ||
+ | |||
+ | < | ||
+ | |||
+ | are coded. | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | First, the `empty' | + | I understand that this proposal could represent a huge break, anyway I believe that my points above shall not be disregarded in order to strengthen parts of PHP that look flawed or fuzzy so far. Honestly, I still read tons of people out there mocking up PHP for its non-typified nature. Also consider that 1) __semantics__, |
+ | |||
+ | First, the <php>empty()</ | ||
- | Second, I implemented the following version which fixes the above two flaws: | + | Second, I implemented the following version which fixes all the above flaws: |
+ | <PHP> | ||
function is_empty( $input = null ) | function is_empty( $input = null ) | ||
{ | { | ||
- | $ser = @serialize( $input ); | + | $ser = @serialize( $input ); |
- | if ( preg_match( "/ | + | |
- | if ( preg_match( "/ | + | |
- | return preg_match( "/ | + | |
} | } | ||
+ | </ | ||
- | ===== Backward Incompatible Changes ===== | + | Let me first say that I resorted to the < |
- | What breaks, | + | |
+ | < | ||
+ | echo "> | ||
+ | echo "Stage 1: empty, undeclared or null containers (`is_empty' | ||
+ | echo "null value >> is_empty( null ): ".( is_empty( null ) ? " | ||
+ | echo " | ||
+ | echo "empty input >> is_empty() : ".( is_empty() ? " | ||
+ | echo "empty string >> is_empty( \" | ||
+ | echo "empty array >> is_empty( [] ) : ".( is_empty( [] ) ? " | ||
+ | |||
+ | echo "Stage 2: non-empty containers (`is_empty' | ||
+ | echo " | ||
+ | echo " | ||
+ | echo "zero (0) constant value >> is_empty( 0 ) : ".( is_empty( 0 ) ? " | ||
+ | |||
+ | $a; | ||
+ | echo " | ||
+ | |||
+ | $i = 1; | ||
+ | echo " | ||
+ | |||
+ | echo " | ||
+ | echo "non empty array >> is_empty( [ 10 ] ): ".( is_empty( [10] ) ? " | ||
+ | |||
+ | $res = fopen( ' | ||
+ | echo " | ||
+ | echo " | ||
+ | if ( $res !== false ) fclose( $res ); | ||
+ | </ | ||
+ | |||
+ | The above code works correctly covers all cases of basic datatypes | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | List the proposed PHP versions that the feature will be included | + | According to the official policies documented at https:// |
+ | in a major version, hence the new function < | ||
+ | |||
+ | The option of keeping < | ||
===== RFC Impact ===== | ===== RFC Impact ===== | ||
+ | |||
==== To SAPIs ==== | ==== To SAPIs ==== | ||
- | Describe the impact to CLI, Development web server, embedded PHP etc. | + | None |
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
- | Will existing extensions be affected? | + | None |
==== To Opcache ==== | ==== To Opcache ==== | ||
- | It is necessary to develop RFC's with opcache in mind, since opcache is a core extension distributed with PHP. | + | None |
Please explain how you have verified your RFC's compatibility with opcache. | Please explain how you have verified your RFC's compatibility with opcache. | ||
==== New Constants ==== | ==== New Constants ==== | ||
- | Describe any new constants so they can be accurately and comprehensively explained in the PHP documentation. | + | None |
==== php.ini Defaults ==== | ==== php.ini Defaults ==== | ||
- | If there are any php.ini settings then list: | + | None |
- | * hardcoded default values | + | |
- | * php.ini-development values | + | |
- | * php.ini-production values | + | |
===== Open Issues ===== | ===== Open Issues ===== | ||
- | Make sure there are no open issues when the vote starts! | + | None |
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
- | List existing areas/ | + | Just the current nomenclature |
- | + | ||
- | This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise. | + | |
===== Future Scope ===== | ===== Future Scope ===== | ||
- | This section details areas where the feature might be improved in future, but that are not currently proposed in this RFC. | + | None |
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | Include | + | We will probably vote for or against adding |
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | Links to any external patches and tests go here. | + | None |
- | + | ||
- | 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 ===== | ===== Implementation ===== | ||
- | After the project is implemented, | + | Refer to the above code. |
- | - 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 ===== | ===== References ===== | ||
- | Links to external references, discussions | + | No refs or links |
===== Rejected Features ===== | ===== Rejected Features ===== | ||
- | Keep this updated with features that were discussed on the mail lists. | + | None. |
rfc/empty_function.1698666989.txt.gz · Last modified: 2023/10/30 11:56 by alessandro.a.rosa_gmail.com