diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/completion/PHPCompletionItem.java b/php/php.editor/src/org/netbeans/modules/php/editor/completion/PHPCompletionItem.java index 651cb6d1398c..c5e458e61cc7 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/completion/PHPCompletionItem.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/completion/PHPCompletionItem.java @@ -1452,11 +1452,14 @@ protected String getNameAndFunctionBodyForTemplate() { if (phpVersion != null && phpVersion.compareTo(PhpVersion.PHP_70) >= 0) { Collection returnTypes = getBaseFunctionElement().getReturnTypes(); + // check whether the method in question is the constructor. If it is, the return type should not be added. + boolean isConstructor = getBaseFunctionElement() instanceof MethodElement + && ((MethodElement) getBaseFunctionElement()).getName().equals(MethodElement.CONSTRUCTOR_NAME); // we can also write a union type in phpdoc e.g. @return int|float // check whether the union type is actual declared return type to avoid adding the union type for phpdoc - if (returnTypes.size() == 1 + if (!isConstructor && (returnTypes.size() == 1 || getBaseFunctionElement().isReturnUnionType() - || getBaseFunctionElement().isReturnIntersectionType()) { + || getBaseFunctionElement().isReturnIntersectionType())) { String returnType = getBaseFunctionElement().asString(PrintAs.ReturnTypes, typeNameResolver, phpVersion); if (StringUtils.hasText(returnType)) { boolean nullableType = CodeUtils.isNullableType(returnType);