diff --git a/include/class_config.inc b/include/class_config.inc
index 9318e13cbcb193602f2b2cbcb41586ee77cc3827..2b1bedbc6337dcb1b98fdcf4484298f404365f86 100644
--- a/include/class_config.inc
+++ b/include/class_config.inc
@@ -308,7 +308,7 @@ class config
   {
     global $ui;
 
-    if ($this->ldapLink === NULL || !is_resource($this->ldapLink->cid)) {
+    if (($this->ldapLink === NULL) || ($this->ldapLink->cid === FALSE)) {
       /* Build new connection */
       $this->ldapLink = LDAP::init($this->current['SERVER'], $this->current['BASE'],
           $this->current['ADMINDN'], $this->get_credentials($this->current['ADMINPASSWORD']));
diff --git a/include/class_ldap.inc b/include/class_ldap.inc
index df420ee05f08ea6f973110e0f7f431ffc4201968..1525896849f923b3bf6a2a8826f0d7599c81c988 100644
--- a/include/class_ldap.inc
+++ b/include/class_ldap.inc
@@ -37,8 +37,12 @@ class LDAP
   var $reconnect      = FALSE;
   var $tls            = FALSE;
 
-  /* connection identifier */
-  var $cid;
+  /**
+   * Connection identifier
+   *
+   * @var resource|object|false
+   */
+  var $cid            = FALSE;
 
   var $hasres         = [];
   var $sr             = [];
@@ -294,7 +298,7 @@ class LDAP
   function unbind ()
   {
     @ldap_unbind($this->cid);
-    $this->cid = NULL;
+    $this->cid = FALSE;
     logging::debug(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, '', 'unbind');
   }
 
@@ -306,6 +310,7 @@ class LDAP
     if ($this->hascon) {
       @ldap_close($this->cid);
       $this->hascon = FALSE;
+      $this->cid    = FALSE;
     }
     logging::debug(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, '', 'disconnect');
   }
@@ -769,9 +774,8 @@ class LDAP
       $r = ldap_rename($this->cid, $source, $dest_rdn, $parent, TRUE);
       $this->error = ldap_error($this->cid);
 
-      /* Check if destination dn exists, if not the
-          server may not support this operation */
-      $r &= is_resource($this->dn_exists($dest));
+      /* Check if destination dn exists, if not the server may not support this operation */
+      $r &= $this->dn_exists($dest);
       logging::debug(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $this->error, 'rename("'.$source.'","'.$dest.'")');
       return $r;
     } else {
@@ -1119,7 +1123,7 @@ class LDAP
     if ($this->error == 'Success') {
       return 0;
     } else {
-      return ldap_errno($this->cid);
+      return @ldap_errno($this->cid);
     }
   }
 
@@ -1202,7 +1206,7 @@ class LDAP
 
     // Try to open the process
     $process = proc_open($cmd, $descriptorspec, $pipes);
-    if (is_resource($process)) {
+    if ($process !== FALSE) {
       // Write the password to stdin
       fclose($pipes[0]);
 
@@ -1221,10 +1225,10 @@ class LDAP
     return $res;
   }
 
-  function dn_exists ($dn)
+  function dn_exists ($dn): bool
   {
     logging::debug(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, '', 'dn_exists('.$dn.')');
-    return @ldap_read($this->cid, $dn, "(objectClass=*)", ["objectClass"]);
+    return (@ldap_read($this->cid, $dn, '(objectClass=*)', ['objectClass']) !== FALSE);
   }
 
   function parseLdif (string $str_attr): array
diff --git a/include/class_logging.inc b/include/class_logging.inc
index 1e4c79a16870321775b074e4389f2616ed5efa34..153ea921af4fa7af8d08bbcbe7901ac9a970bb9a 100644
--- a/include/class_logging.inc
+++ b/include/class_logging.inc
@@ -112,40 +112,43 @@ class logging
     global $config;
 
     static $first = TRUE;
-    if (($_SERVER['REQUEST_METHOD'] == 'POST') && preg_match('/index.php$/', $_SERVER['REQUEST_URI'])) {
-      return;
-    }
 
     if (session::get('DEBUGLEVEL') & $level) {
+      $output = '';
       if ($first) {
-        echo '<div id="debug-handling" class="notice">'.
+        $output .= '<div id="debug-handling" class="notice">'.
               '<img src="geticon.php?context=status&amp;icon=dialog-information&amp;size=22" alt="Information" style="vertical-align:middle;margin-right:.2em;"/>'.
               'There is some debug output '.
               '<button onClick="javascript:$$(\'div.debug_div\').each(function (a) { a.toggle(); });">Toggle</button>'.
             '</div>';
         $first = FALSE;
       }
-      $output = "DEBUG[$level] ";
+      $logline = "DEBUG[$level] ";
       if ($function != '') {
-        $output .= "($file:$function():$line) - $info: ";
+        $logline .= "($file:$function():$line) - $info: ";
       } else {
-        $output .= "($file:$line) - $info: ";
+        $logline .= "($file:$line) - $info: ";
       }
-      echo '<div class="debug_div">';
-      echo $output;
-      $logline = $output;
+      $output .= '<div class="debug_div">';
+      $output .= $logline;
       if (is_array($data)) {
-        print_a($data);
+        $output .= print_a($data, TRUE);
         $logline .= print_r($data, TRUE);
       } else {
-        echo "'$data'";
-        $logline .= "'$data'";
+        $output   .= "'$data'";
+        $logline  .= "'$data'";
       }
-      echo "</div>\n";
+      $output .= "</div>\n";
 
       if (is_object($config) && preg_match('/true/i', $config->get_cfg_value('debugLogging', ''))) {
         fusiondirectory_log($logline);
       }
+
+      if (($_SERVER['REQUEST_METHOD'] == 'POST') && preg_match('/index.php$/', $_SERVER['REQUEST_URI'])) {
+        return;
+      }
+
+      echo $output;
     }
   }
 
diff --git a/include/class_userinfo.inc b/include/class_userinfo.inc
index 855931de3600d198814ef96c18991408d409b145..583612c459f27ae4a96e380a89d731b28a2fc0df 100644
--- a/include/class_userinfo.inc
+++ b/include/class_userinfo.inc
@@ -87,6 +87,9 @@ class userinfo
     $ldap = $config->get_ldap_link();
     $ldap->cat($this->dn, ['*']);
     $attrs = $ldap->fetch(TRUE);
+    if (!$ldap->success()) {
+      throw new FusionDirectoryLdapError($this->dn, LDAP_SEARCH, $ldap->get_error(), $ldap->get_errno());
+    }
 
     $this->uid = $attrs['uid'][0];
 
diff --git a/include/simpleplugin/class_Attribute.inc b/include/simpleplugin/class_Attribute.inc
index 190cd6c26287236d82940bd6645949c78aa4fe4c..98d200a9eebbc90bbd85244480674ed5551728d1 100644
--- a/include/simpleplugin/class_Attribute.inc
+++ b/include/simpleplugin/class_Attribute.inc
@@ -664,13 +664,12 @@ class Attribute
   function serializeAttribute (array &$attributes, bool $form = TRUE)
   {
     if (!$form || $this->visible) {
-      $class = get_class($this);
-      while ($class != 'Attribute') {
+      $class  = get_class($this);
+      $type   = [];
+      while ($class != FALSE) {
         $type[] = $class;
         $class  = get_parent_class($class);
       }
-      /* Avoid empty array */
-      $type[] = 'Attribute';
       $infos = [
         'htmlid'      => $this->getHtmlId(),
         'label'       => $this->getLabel(),