Check also inheritance in type checking of isChild to prevent exceptions

This commit is contained in:
Jan Böhmer 2019-09-18 12:48:27 +02:00
parent 2cfad83ee8
commit 842ee145bc

View file

@ -146,8 +146,9 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
{ {
$class_name = \get_class($this); $class_name = \get_class($this);
//Check if both elements compared, are from the same type: //Check if both elements compared, are from the same type
if ($class_name !== \get_class($another_element)) { // (we have to check inheritance, or we get exceptions when using doctrine entities (they have a proxy type):
if (!is_a($another_element, $class_name) && !is_a($this, get_class($another_element))) {
throw new \InvalidArgumentException('isChildOf() only works for objects of the same type!'); throw new \InvalidArgumentException('isChildOf() only works for objects of the same type!');
} }