Web:S6827 - False Positive in Web with PHP Short Echo Syntax

Language: PHP (PHTML)

Rule: Web:S6827 - Anchors must have content and the content must be accessible by a screen reader

Why do you believe it’s a false positive?

The rule incorrectly reports an issue when anchor content is rendered using PHP short echo syntax (<?= ... ?>).

The analyzer appears to treat the anchor as empty when the content is provided through a short echo tag, even though the same code is correctly recognized when written using the equivalent standard PHP syntax (<?php echo ... ?>).

Since both syntaxes produce identical HTML output, they should be analyzed consistently.

How can we reproduce the problem?

The following code raises Web:S6827:

<?php $linkText = "Link"; ?>
<a href="javascript:void(0)"><?= $linkText ?></a>

However, the equivalent code does not raise the issue:

<?php $linkText = "Link"; ?>
<a href="javascript:void(0)"><?php echo $linkText; ?></a>

Both snippets render the same HTML:

<a href="javascript:void(0)">Link</a>

Expected behavior

Both <?= $linkText ?> and <?php echo $linkText; ?> should be treated identically, and no Web:S6827 issue should be raised.

Actual behavior

Web:S6827 is raised when using PHP short echo syntax (<?= ... ?>) but not when using the equivalent <?php echo ... ?> syntax.

Hello @yogesh-encora,

thanks for reporting this. Indeed this is a FP. We created an Jira ticket to fix this together with your other report

Cheers