mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Check also inheritance in type checking of isChild to prevent exceptions
This commit is contained in:
parent
2cfad83ee8
commit
842ee145bc
1 changed files with 3 additions and 2 deletions
|
@ -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!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue