cast(): fix strpos(): Passing null to parameter #1 () of type string is deprecated

This commit is contained in:
Benjamin Renard 2024-12-13 15:22:38 +01:00
parent e9fb4cf504
commit 88b22ca22b
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -91,7 +91,7 @@ function ensure_is_array($value) {
* Get a specific configuration variable value
*
* @param mixed $value The value to cast
* @param string $type The type of expected value. The configuration variable
* @param string|null $type The type of expected value. The configuration variable
* value will be cast as this type. Could be : bool, int,
* float or string.
* @param bool $split If true, $type=='array' and $value is a string, split
@ -99,7 +99,7 @@ function ensure_is_array($value) {
* @return mixed The cast value
**/
function cast($value, $type, $split=false) {
if (strpos($type, 'array_of_') === 0) {
if (is_string($type) && strpos($type, 'array_of_') === 0) {
$type = substr($type, 9);
$values = array();
foreach(ensure_is_array($value) as $key => $value)