Skip to content

Commit

Permalink
Merge pull request #215 from wmde/ImproveHashArrayTypeErrorMessage
Browse files Browse the repository at this point in the history
Show better error for "wrong" objects in HashArray
  • Loading branch information
filbertkm committed Oct 1, 2014
2 parents d8f673d + 2f05015 commit 5875353
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/HashArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,11 @@ protected function hasValidType( $value ) {
*/
protected function setElement( $index, $value ) {
if ( !$this->hasValidType( $value ) ) {
$type = is_object( $value ) ? get_class( $value ) : gettype( $value );

throw new InvalidArgumentException(
'Can only add ' . $this->getObjectType() . ' implementing objects to ' . get_called_class() . '.'
'Can only add ' . $this->getObjectType() . ' implementing objects to ' . get_called_class() . ', ' .
'but found a ' . $type . ' instead'
);
}

Expand Down

0 comments on commit 5875353

Please sign in to comment.