php - Cleaner way to write this check? -
i have following 2 arrays (var_dumped
):
array (size=3) 'param' => array (size=1) 0 => string 'example' (length=7) 'page-template' => string 'general' (length=7) 'action' => object(closure)[2125] array (size=3) 'param' => array (size=1) 0 => string 'example' (length=7) 'page-template' => string 'general' (length=7) 'action' => object(closure)[2126]
now same, call same function (in 'action'
) cannot ===
on them because of closure, wrote check:
foreach(self::$registeredroutes[$routename] $routeactions) { if (!is_callable($action) && !is_callable($routeactions)) { if (isset($routeactions['param']) && isset($action['param']) && $routeactions['param'] === $action['param'] && isset($routeactions['page-template']) && isset($action['page-template']) && $routeactions['page-template'] === $action['page-template'] ) { var_dump('hello'); } } }
accept makes me want vomit because of if statement. there cleaner, testable way of writing still same result?
now same, call same function
apparently not.
$func = function() { // ... }; $arr1 = array( 'param' => array('example'), 'page-template' => 'general', 'action' => $func); $arr2 = array( 'param' => array('example'), 'page-template' => 'general', 'action' => $func); var_dump($arr1 === $arr2); // true
you can don't use anonymous functions.
Comments
Post a Comment