Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: five minus one?
(Example: nine)

The Note You're Voting On

rnealxp at yahoo dot com
5 years ago
Please use this corrected version of function "valuesAreIdentical" instead of that which I previously posted (dependencies found in previous post); if an Admin can just replace the fn snippet, awesome/thanks, otherwise, apologies.
<?php
public static function valuesAreIdentical($v1, $v2):bool{
$type1 = gettype($v1);
$type2 = gettype($v2);
switch(
true){
case (
$type1 !== $type2):
return
false;
case (
$type1==='boolean' || $type1==='integer' || $type1==='double' || $type1==='string'):
//Do strict comparison here.
return ($v1===$v2);
case (
$type1==='array'):
return
self::arraysAreIdentical($v1, $v2);
case (
$type1==='object'):
return
self::objectsAreIdentical($v1,$v2);
case (
$type1==='NULL'):
//Since both types were of type NULL, consider their "values" equal.
return true;
case (
$type1==='resource' || $type1==='unknown type'):
//How to compare if at all?
return true;
default:
return
true; //Code-flow not intended to arrive here.
} //end switch
}
?>

<< Back to user notes page

To Top