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 revisionBoth sides next revision
rfc:strict_operators:faq [2020/07/06 11:50] jasnyrfc:strict_operators:faq [2020/07/06 13:46] jasny
Line 57: Line 57:
 Strict comparison of arrays as unsorted hashmaps currently isn't possible and requires sorting the array, prior to comparison. Strict comparison of arrays as unsorted hashmaps currently isn't possible and requires sorting the array, prior to comparison.
  
-With ''%%==%%'' unavailable when using strict_operators, sorting the array would be the only option available.+With ''%%==%%'' unavailable when using strict_operators, sorting the array is the only option available. 
 + 
 +<code php> 
 +ksort($array1); 
 +ksort($array2); 
 + 
 +$array1 === $array2; 
 +</code>
  
 Array functions might be added to compare arrays in different ways. But that's outside the scope of this RFC. Array functions might be added to compare arrays in different ways. But that's outside the scope of this RFC.
 +
 +==== How can objects be compared by property? ====
 +
 +With the ''=='' operator, two object instances are equal if they have the same attributes and values, and are instances of the same class. Values are compared with ''=='', applying type juggling. Using ''==='' will check if the objects are the same instance.
 +
 +When using strict_operators, ''=='' with objects will always throw a ''TypeError''. With ''%%==%%'' unavailable, ''get_object_vars'' needs to be used.
 +
 +
 +<code php>
 +get_class($object1) === get_class($object2) && get_object_vars($object1) === get_object_vars($object2);
 +</code>
 +
  
 ==== Why isn't is allowed to increment strings with strict_operators? ==== ==== Why isn't is allowed to increment strings with strict_operators? ====
rfc/strict_operators/faq.txt · Last modified: 2020/07/06 15:01 by jasny