protected function isCharInComment($haystack, $charPosition)
    {
        // check for line comment
        for ($c = $charPosition; $c > 0; --$c) {
            if ($haystack[$c] === PHP_EOL) {
                break;
            } elseif ($haystack[$c] === '#' or ($haystack[$c] === '/'
                    and ($haystack[$c + 1] === '/' or $haystack[$c - 1] === '/'))
            ) {
                return true;
            }
        }
        // check for block comment
        $openingsCount = 0;
        $closingsCount = 0;
        for ($c = $charPosition; $c > 0; --$c) {
            if ($haystack[$c] === '*' and $haystack[$c - 1] === '/') {
                ++$openingsCount;
            }
            if ($haystack[$c] === '/' and $haystack[$c - 1] === '*') {
                ++$closingsCount;
            }
        }
        if ($openingsCount !== $closingsCount) {
            return true;
        }
        return false;
    }