         # Get chain of all scopes
         chain = editor.scopeDescriptorForBufferPosition([row, character]).getScopeChain()
 
-        # }
-        if chain.indexOf("scope.end") != -1
-          closedBlocks++
-        # {
-        else if chain.indexOf("scope.begin") != -1
-          openedBlocks++
-
+        # NOTE: Atom quirk: both line.length and line.length - 1 return the same scope descriptor, BUT you can't skip
+        # scanning line.length as sometimes line.length - 1 does not return a scope descriptor at all.
+        if not (character == line.length and chain == lastChain)
+          # }
+          if chain.indexOf("scope.end") != -1
+            closedBlocks++
+          # {
+          else if chain.indexOf("scope.begin") != -1
+            openedBlocks++
+
+        # NOTE: atom/language-php quirk, when you open a closure definition, it's opening brace does NOT have the
+        # 'scope.begin' class. See also https://github.com/atom/language-php/issues/98 .
+        if chain.indexOf('.meta.function.closure.php') != -1
+          if not isInClosure
+            isInClosure = true
+            openedBlocks++
+
+        else
+          isInClosure = false
+
+        lastChain = chain
         character++
 
       # Get chain of all scopes


      character = 0
      lineLength = line.length

      # Scan the entire line, fetching the scope for each character position as one line can contain both a scope start
      # and end such as "} elseif (true) {". Here the scope descriptor will differ for different character positions on

    closedBlocks = 0

    result = false
    isInClosure = false

    # for each row
    while row != -1
