Added exception for enumerated array (#9644)

\SilverStripe\View\ArrayData::__construct() throws error when passed an enumerated array #9644
This commit is contained in:
Dylan Grech 2020-08-22 13:48:59 +02:00 committed by GitHub
parent 009ae3ee4f
commit a380cc7444
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,10 +33,16 @@ 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)) {
$this->array = $value; if (ArrayLib::is_associative($value)) {
} elseif (is_array($value) && count($value) === 0) { $this->array = $value;
$this->array = []; } elseif (count($value) === 0) {
$this->array = array();
} else {
$message = 'Parameter to ArrayData constructor needs to be an object or associative array,
enumareted array passed instead. Did you mean to use ArrayList?';
throw new InvalidArgumentException($message);
}
} else { } else {
$message = 'Parameter to ArrayData constructor needs to be an object or associative array'; $message = 'Parameter to ArrayData constructor needs to be an object or associative array';
throw new InvalidArgumentException($message); throw new InvalidArgumentException($message);