rfc:empty_function

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:empty_function [2023/10/31 11:44] – Under Discussion alessandro.a.rosa_gmail.comrfc:empty_function [2023/10/31 16:42] (current) – Under Discussion alessandro.a.rosa_gmail.com
Line 7: Line 7:
  
 ===== Introduction ===== ===== Introduction =====
-The official documentation of the function ''empty()'' is at https://www.php.net/manual/en/function.empty.php. All the quotations below have been reported from the online version up to the date of this RFC, namely October 31th 2023.+The official documentation of the function <php>empty()</php> is at https://www.php.net/manual/en/function.empty.php. All the quotations below have been reported from the online version up to the date of this RFC, namely October 31th 2023.
  
-Here the purpose of the function ''empty()'' is to `//Determine whether a variable is considered to be empty//'. Before exploring the behavior of this built-in function, we would argue upon the following sentence: `//A variable is considered empty if it does not exist or if its value equals false//'. While we agree on the first part, we could not do about the second half, as it throws an exception about the meaning of `//emptiness//'.+Here the purpose of the function <php>empty()</php> is to `//Determine whether a variable is considered to be empty//'. Before exploring the behavior of this built-in function, we would argue upon the following sentence: `//A variable is considered empty if it does not exist or if its value equals false//'. While we agree on the first part, we could not do about the second half, as it throws an exception about the meaning of `//emptiness//'.
  
 Defining `emptiness' might be very a subtle argument and actually not all the most blasoned online dictionaries succeed in giving a quite insightful definition. First, Defining `emptiness' might be very a subtle argument and actually not all the most blasoned online dictionaries succeed in giving a quite insightful definition. First,
Line 22: Line 22:
 > Dictionary.com: `//the fact or state of containing nothing or of being without the usual or appropriate contents//'. > Dictionary.com: `//the fact or state of containing nothing or of being without the usual or appropriate contents//'.
  
-Before our conclusions, I will first resume basic notions about variable declaration; each example is followed by some equivalent statement in C-like languages, as they are pretty clearer about the strict connection between the kind of containers and contents.+Before our conclusions, I will first resume basic notions about variable declaration; each example is followed by some equivalent statement in C-family languages, as they are pretty clearer about the strict connection between the kind of containers and contents.
  
 <PHP> <PHP>
Line 29: Line 29:
 $integer = 1; $integer = 1;
  
-//In C-like languages, it will ruled through this instantiation+//In C-family languages, it will ruled through this instantiation
 //int <var_name> = 1; //int <var_name> = 1;
 </PHP> </PHP>
Line 42: Line 42:
 $float = 1.1; $float = 1.1;
  
-//In C-like languages, it will ruled through this instantiation+//In C-family languages, it will ruled through this instantiation
 //double <var_name> = 1.1; //double <var_name> = 1.1;
 </PHP> </PHP>
Line 55: Line 55:
 $string = "<any or no character>"; $string = "<any or no character>";
  
-//In C-like languages, it corresponds to the pointer-like syntax+//In C-family languages, it corresponds to the pointer-like syntax
 //char* <var_name> = "<any or no characters>"; //char* <var_name> = "<any or no characters>";
 </PHP> </PHP>
Line 65: Line 65:
 are coded. are coded.
  
-We conclude that the definition of `emptiness' changes according to the kind of container. Therefore the second option in the official definition of emptiness in the empty function documentation, namely `//a variable is considered empty if its value equals false//', cannot logically holds, with regard to the essence of the variable container. The constant boolean value `''false''' alludes to the instantiation of a one-byte container, which is filled through the `''false''' constant value, hence the one-byte container cannot be judged as `empty'. Moreover, the same objection holds for the zero (0) input value, according to the official return value of ''empty()'' function in php.net, being documented as follows:+We conclude that the definition of `emptiness' changes according to the kind of container. Therefore the second option in the official definition of emptiness in the empty function documentation, namely `//a variable is considered empty if its value equals false//', cannot logically holds, with regard to the essence of the variable container. The constant boolean value `''false''' alludes to the instantiation of a one-byte container, which is filled through the `''false''' constant value, hence the one-byte container cannot be judged as `empty'. Moreover, the same objection holds for the zero (0) input value, according to the official return value of <php>empty()</php> function in php.net, being documented as follows:
 `//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//'. `//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: 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**: 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.+1) the **semantics**: the function name is ambiguous about the action, that is, it is not clear whether the goal of <php>empty()</php> function should consist of testing the `emptiness' of input variable or return an empty version of the input variable.
  
 2) the **behavior**. The only three issues arise from inputing no variable or managing the false and 0 constant values. 2) the **behavior**. The only three issues arise from inputing no variable or managing the false and 0 constant values.
Line 168: Line 168:
 According to the official policies documented at https://wiki.php.net/rfc/releaseprocess, backwards compatibility can only be broken According to the official policies documented at https://wiki.php.net/rfc/releaseprocess, backwards compatibility can only be broken
 in a major version, hence the new function <php>is_empty()</php> would appear not before than version 9.0 in a major version, hence the new function <php>is_empty()</php> would appear not before than version 9.0
 +
 +The option of keeping <php>empty()</php> function together with ''is_empty()'' is fine too, so deprecation is not required: backward compatibility would be saved, though I would recommend the usage of ''is_empty()'' however.
  
 ===== RFC Impact ===== ===== RFC Impact =====
rfc/empty_function.1698752696.txt.gz · Last modified: 2023/10/31 11:44 by alessandro.a.rosa_gmail.com