2

In app/models/Model this validates

//simulating incorrect user input
//$model->status='some-string';

public function rules()
{
    return [
        ['status', 'in', 'range' => [0]], //asserts true (why?)
      //['status', 'in', 'range' => [0], 'strict' => true], //asserts false (correct)

    ];
}

EDIT: I have updated this question to reflect new insights.

Decimoseptimo
  • 103
  • 11

2 Answers2

0

Please make sure you define your constant inside in model class

 class model extends activeRecord {
const STATUS = 0;
public function rules()
{
    return [
        [['status'], 'in', 'range' => [self::STATUS]],
    ];
}
}

Try this it works for me.....

Dani
  • 905
  • 7
  • 14
0

status is most likely empty at the time of the validation, the internal checks compute to something like:

// non-strict:
null == 0  // this is true

// strict:
null === 0 // this is false

same applies with empty string, see related question

Community
  • 1
  • 1
csminb
  • 2,382
  • 1
  • 16
  • 27