Merge pull request #9650 from dylangrech92/patch-1

Added exception for enumerated array (#9644)
This commit is contained in:
Daniel Hensby 2020-09-07 10:57:36 +01:00 committed by GitHub
commit 85242b1efe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,12 +33,18 @@ class ArrayData extends ViewableData
{ {
if (is_object($value)) { if (is_object($value)) {
$this->array = get_object_vars($value); $this->array = get_object_vars($value);
} elseif (ArrayLib::is_associative($value)) { } elseif (is_array($value)) {
if (ArrayLib::is_associative($value)) {
$this->array = $value; $this->array = $value;
} elseif (is_array($value) && count($value) === 0) { } elseif (count($value) === 0) {
$this->array = []; $this->array = [];
} else { } else {
$message = 'Parameter to ArrayData constructor needs to be an object or associative array'; $message = 'ArrayData constructor expects an object or associative array,
enumerated array passed instead. Did you mean to use ArrayList?';
throw new InvalidArgumentException($message);
}
} else {
$message = 'ArrayData constructor expects an object or associative array';
throw new InvalidArgumentException($message); throw new InvalidArgumentException($message);
} }
parent::__construct(); parent::__construct();