PHP function to evaluate comparisons between two values, with debug logging The following method works fine but it is rather verbose:

private function performComparison($element, $operator, $value_allowed, $value_entered)
{
    switch($operator):
        case '&gt;':
            $result = ($value_entered &gt;  $value_allowed) ? true : false;
            break;
        case '&gt;=':
            $result = ($value_entered &gt;= $value_allowed) ? true : false;
            break;
        case '&lt;':
            $result = ($value_entered &lt;  $value_allowed) ? true : false;
            break;
        case '&lt;=':
            $result = ($value_entered &lt;= $value_allowed) ? true : false;
            break;
        case '=':
            $result = ($value_entered == $value_allowed) ? true : false;
            break;
    endswitch;
        $dateformat = 'n/j/Y';
        $debug = ['element' =&gt; $element, 'operator' =&gt; $operator, 'value allowed' =&gt; is_a($value_allowed, 'DateTime') ? $value_allowed-&gt;format($dateformat) : $value_allowed, 'value entered' =&gt; is_a($value_entered, 'DateTime') ? $value_entered-&gt;format($dateformat) : $value_entered, 'result' =&gt; ($result === false) ? 'false' : 'true'];
        echo '&lt;pre&gt;'.print_r($debug,1).'&lt;/pre&gt;';
    return $result;
}


Note that the 3 lines of code just before the return $result; line are very helpful for debugging in the Development phase so I'd like to keep those.

In an attempt to make a more concise version of this method I came up with the following:

private function performComparison($element, $operator, $value_allowed, $value_entered)
{
    $comparisonFunctions = [
        '&gt;' =&gt; function($value_allowed, $value_entered) { return ($value_entered &gt;  $value_allowed) ? true : false; },
        '&gt;='    =&gt; function($value_allowed, $value_entered) { return ($value_entered &gt;= $value_allowed) ? true : false; },
        '&lt;' =&gt; function($value_allowed, $value_entered) { return ($value_entered &lt;  $value_allowed) ? true : false; },
        '&lt;='    =&gt; function($value_allowed, $value_entered) { return ($value_entered &lt;= $value_allowed) ? true : false; },
        '=' =&gt; function($value_allowed, $value_entered) { return ($value_entered == $value_allowed) ? true : false; }
    ];

    $result = array_key_exists($operator, $comparisonFunctions) ? $comparisonFunctions[$operator]($value_allowed, $value_entered) : null;
        $dateformat = 'n/j/Y';
        $debug = ['element' =&gt; $element, 'operator' =&gt; $operator, 'value allowed' =&gt; is_a($value_allowed, 'DateTime') ? $value_allowed-&gt;format($dateformat) : $value_allowed, 'value entered' =&gt; is_a($value_entered, 'DateTime') ? $value_entered-&gt;format($dateformat) : $value_entered, 'result' =&gt; ($result === false) ? 'false' : 'true'];
        echo '&lt;pre&gt;'.print_r($debug,1).'&lt;/pre&gt;';
    return $result;
}


This version also works fine but I'm wondering if there are any ways it could be condensed further.
given your function's purpose is to return the calculation result, I would return the expression result right away, especially given return makes break unnecessary as well

private function performComparison($operator, $value_allowed, $value_entered)
{
    switch($operator) {
        case '&gt;':
            return ($value_entered &gt;  $value_allowed);
        case '&gt;=':
            return ($value_entered &gt;= $value_allowed);
        case '&lt;':
            return ($value_entered &lt;  $value_allowed);
        case '&lt;=':
            return ($value_entered &lt;= $value_allowed);
        case '=':
            return ($value_entered == $value_allowed);
        default:
            throw new InvalidArgumentException("Invalid operator");
    }
}


The code above is both concise and readable, it takes one no problem to gist the function's meaning and purpose. 

Whereas any debugging should be done elsewhere. If you need any debugging for this function, create another one encapsulating the current function's call.

    private function debugPerformComparison($element, $operator, $value_allowed, $value_entered)
    {
        $result = $this-&gt;performComparison($operator, $value_allowed, $value_entered);
        $dateformat = 'n/j/Y';
        $debug = [
            'element' =&gt; $element, 
            'operator' =&gt; $operator, 
            'value allowed' =&gt; is_a($value_allowed, 'DateTime') ? $value_allowed-&gt;format($dateformat) : $value_allowed, 
            'value entered' =&gt; is_a($value_entered, 'DateTime') ? $value_entered-&gt;format($dateformat) : $value_entered, 
            'result' =&gt; $result,
        ];
        echo '&lt;pre&gt;'.var_export($debug,1).'&lt;/pre&gt;';
        return $result;
    }


Regarding anonymous function-based version, a concise version shouldn't be less readable in the first place. Any code improvements should improve the readability, by means of removing unnecessary parts, not worsen it. And the said version is extremely hard to read.