The expression $this->isPrimitive($type) of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.
In PHP, under loose comparison (like ==, or !=, or switch conditions),
values of different types might be equal.
For string values, the empty string '' is a special case, in particular
the following results might be unexpected:
''==false// true''==null// true'ab'==false// false'ab'==null// false// It is often better to use strict comparison''===false// false''===null// false
Loading history...
26
4
$value = new $type($this->typeData[$offset]);
27
4
$this->typeData[$offset] = $value;
28
}
29
28
}
30
31
/**
32
* @param $type
33
* @param Context|callable $context
34
* @return $this
35
*/
36
30
public static function ofType($type, $context = null)
37
{
38
30
$set = static::of($context);
39
30
return $set->setType($type);
40
}
41
42
/**
43
* @param $type
44
* @param array $data
45
* @param Context|callable $context
46
* @return $this
47
*/
48
27
public static function ofTypeAndData($type, array $data, $context = null)
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: