phalcon/cphalcon · error · Phalcon\Html\Exceptions\FriendlyTitleConversionFailed

{message}

Error message

{message}

What it means

The FriendlyTitle HTML helper converts text into a URL-friendly title (separator handling, lowercasing, regex replacement). Its __invoke wraps that conversion pipeline in a try/catch and rethrows any failure as FriendlyTitleConversionFailed carrying the original message, so conversion-level problems — most commonly invalid UTF-8 bytes fed to the PCRE functions — surface as one dedicated exception type.

Source

Thrown at phalcon/Html/Helper/FriendlyTitle.zep:62

     * @param string     $separator
     * @param bool       $lowercase
     * @param mixed|null $replace
     *
     * @return string
     * @throws Exception
     */
    public function __invoke(
        string text,
        string separator = "-",
        bool lowercase = true,
        var replace = null
    ) -> string {
        var ex;

        try {
            return this->friendly->__invoke(text, separator, lowercase, replace);
        } catch \Exception, ex {
            throw new FriendlyTitleConversionFailed(ex->getMessage());
        }
    }
}

View on GitHub (pinned to b7419de9cd)

Solutions

  1. Sanitize input before conversion: $text = mb_convert_encoding($text, 'UTF-8', mb_detect_encoding($text))
  2. Strip invalid sequences: $text = iconv('UTF-8', 'UTF-8//IGNORE', $text)
  3. Ensure the mbstring extension is installed and enabled

Example fix

// before
$title = $this->tag->friendlyTitle($article->title); // legacy-encoded bytes

// after
$title = $this->tag->friendlyTitle(
    mb_convert_encoding($article->title, 'UTF-8', 'UTF-8')
);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!mb_check_encoding($text, 'UTF-8')) {
    $text = mb_convert_encoding($text, 'UTF-8', 'UTF-8'); // drops invalid sequences
}

$title = $this->tag->friendlyTitle($text, '-', true);

Type guard

function isSafeTitleText(string $text): bool
{
    return mb_check_encoding($text, 'UTF-8');
}

Try / catch

try {
    $title = $this->tag->friendlyTitle($text, '-', true);
} catch (\Phalcon\Html\Exceptions\FriendlyTitleConversionFailed $e) {
    // fallback: transliterate/strip, then retry once
    $title = $this->tag->friendlyTitle(
        iconv('UTF-8', 'UTF-8//IGNORE', $text), '-', true
    );
}

Prevention

When it happens

Trigger: Calling the friendlyTitle helper ($this->tag->friendlyTitle($text) or the FriendlyTitle helper via TagFactory) with byte sequences that are not valid UTF-8, which makes the internal preg_replace return null and throw; running the pipeline without the mbstring extension.

Common situations: User-submitted or legacy-encoded (ISO-8859-1/Windows-1252) strings used as titles; data imported from spreadsheets or feeds; binary garbage reaching the title helper through unvalidated input.

Related errors


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/98bae01d44266b31. Report an issue: GitHub.