src/Koldy/Validator.php
protected function validateDifferent($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        if (count($args) == 0) {
            throw new ValidatorConfigException("Validator 'different' must have argument in validator list for parameter {$parameter}");
        }

        $differentAsField = trim($args[0]);

        if (strlen($differentAsField) == 0) {
            throw new ValidatorConfigException("Validator 'different' must have non-empty argument; parameter={$parameter}");
        }

	    $present = $this->validatePresent($value, $differentAsField, [], $rules, $context);
        if ($present !== null) {
            return $present;
        }

        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (!is_scalar($value)) {
            return Message::getMessage(Message::PRIMITIVE, [
                'param' => $parameter
            ]);
        }

        $differentAsValue = $context[$differentAsField] ?? null;

        if (!is_scalar($differentAsValue)) {
            return Message::getMessage(Message::PRIMITIVE, [
                'param' => $differentAsField
            ]);
        }

        if ($value == $differentAsValue) {
            return Message::getMessage(Message::DIFFERENT, [
                'param' => $parameter,
                'value' => $value,
                'otherField' => $differentAsField,
                'otherValue' => $differentAsValue
            ]);
        }

        return null;
    }
protected function validateDifferent($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        if (count($args) == 0) {
            throw new ValidatorConfigException("Validator 'different' must have argument in validator list for parameter {$parameter}");
        }

        $differentAsField = trim($args[0]);

        if (strlen($differentAsField) == 0) {
            throw new ValidatorConfigException("Validator 'different' must have non-empty argument; parameter={$parameter}");
        }

	    $present = $this->validatePresent($value, $differentAsField, [], $rules, $context);
        if ($present !== null) {
            return $present;
        }

        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (!is_scalar($value)) {
            return Message::getMessage(Message::PRIMITIVE, [
                'param' => $parameter
            ]);
        }

        $differentAsValue = $context[$differentAsField] ?? null;

        if (!is_scalar($differentAsValue)) {
            return Message::getMessage(Message::PRIMITIVE, [
                'param' => $differentAsField
            ]);
        }

        if ($value == $differentAsValue) {
            return Message::getMessage(Message::DIFFERENT, [
                'param' => $parameter,
                'value' => $value,
                'otherField' => $differentAsField,
                'otherValue' => $differentAsValue
            ]);
        }

        return null;
    }
protected function validateDifferent ( $ value , string $ parameter , array $ args = [ ] , array $ rules = null , array $ context = null ) : ? string { if ( count ( $ args ) == 0 ) { throw new ValidatorConfigException ( "Validator 'different' must have argument in validator list for parameter {$parameter}" ) ; } $ differentAsField = trim ( $ args [ 0 ] ) ; if ( strlen ( $ differentAsField ) == 0 ) { throw new ValidatorConfigException ( "Validator 'different' must have non-empty argument; parameter={$parameter}" ) ; } $ present = $ this -> validatePresent ( $ value , $ differentAsField , [ ] , $ rules , $ context ) ; if ( $ present !== null ) { return $ present ; } //$value = $this->getValue($parameter); if ( $ value === null ) { return null ; } if ( ! is_scalar ( $ value ) ) { return Message :: getMessage ( Message :: PRIMITIVE , [ 'param' => $ parameter ] ) ; } $ differentAsValue = $ context [ $ differentAsField ] ?? null ; if ( ! is_scalar ( $ differentAsValue ) ) { return Message :: getMessage ( Message :: PRIMITIVE , [ 'param' => $ differentAsField ] ) ; } if ( $ value == $ differentAsValue ) { return Message :: getMessage ( Message :: DIFFERENT , [ 'param' => $ parameter , 'value' => $ value , 'otherField' => $ differentAsField , 'otherValue' => $ differentAsValue ] ) ; } return null ; }
Opposite of "same", passes if value is different then value in other field

@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules

@return null|string
@throws ValidatorConfigException
@example
'param1' => 'required',
'param2' => 'different:param1'
Opposite of same passes if value is different then value in other field