rfc:strict_operators:faq

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
Last revisionBoth sides next revision
rfc:strict_operators:faq [2020/07/06 14:56] – switch is not affected jasnyrfc:strict_operators:faq [2020/07/06 14:59] jasny
Line 46: Line 46:
 Both the concatenation operator and arithmetic operators throw a ''%%TypeError%%'' for arrays, resources, and objects. Casting these to a string or int/float doesn't give a proper representation of the value of the operand. Both the concatenation operator and arithmetic operators throw a ''%%TypeError%%'' for arrays, resources, and objects. Casting these to a string or int/float doesn't give a proper representation of the value of the operand.
  
-Using a boolean or null as operand for both concatenation and arithmetic operators also throws a ''%%TypeError%%''. In most cases, the use of a boolean or null indicates an error as many functions return ''%%false%%'' or ''%%null%%'' in case of an error or when no result can be returned. This is different from the function returning an empty string or ''%%0%%''. [[https://php.net/strpos|''%%strpos%%'']] is a well-known example.+Using a boolean or null as operand for both concatenation and arithmetic operators also throws a ''%%TypeError%%''. In most cases, the use of a boolean or null indicates an error as many functions return ''%%false%%'' or ''%%null%%'' in case of an error or when no result can be returned. This is different from the function returning an empty string or ''%%0%%''. [[https://php.net/strpos|strpos]] is a well-known example.
  
 ==== Will comparing a number to a numeric string work with strict_operators? ==== ==== Will comparing a number to a numeric string work with strict_operators? ====
Line 105: Line 105:
 Changing ''switch'' to compare using ''==='' would change the behavior based on the directive. Changing ''switch'' to compare using ''==='' would change the behavior based on the directive.
  
-To use strict comparison, most ''switch'' statements can be rewritten to [[https://wiki.php.net/rfc/match_expression_v2|''match'' statements].+To use strict comparison, most ''switch'' statements can be rewritten to [[https://wiki.php.net/rfc/match_expression_v2|match statements]].
  
 ==== Are there cases where a statement doesn't throw a TypeError but yields a different result? ==== ==== Are there cases where a statement doesn't throw a TypeError but yields a different result? ====
rfc/strict_operators/faq.txt · Last modified: 2020/07/06 15:01 by jasny