Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Return a formatted string
<?php sprintf(string $format, mixed ...$values): string
<?php         $disableNotice = 'To disable this notice, add --exclude=%1$s to your command or add <exclude name="%1$s.%2$s"/> to your custom ruleset.';



        $message  = ' ' . $delimiterLine;

        $message .= ' ' . \sprintf($disableNotice, $sniffName, $errorCode);

        $message .= ' ' . $delimiterLine;

        $message .= ' ' . 'Thank you for using PHPCompatibility!';
<?php     public function testNewPHPOpenTagEOF($fileNumber, $line)

    {

        $fileName = __DIR__ . '/' . \sprintf(self::TEST_FILE, $fileNumber);



        $file = $this->sniffFile($fileName, '7.3');

        $this->assertError($file, $line, 'A PHP open tag at the end of a file, without trailing newline, was not supported in PHP 7.3 or earlier and would result in a syntax error or be interpreted as a literal string');
<?php     public function testNoFalsePositivesOnLine($fileNumber, $line)

    {

        $fileName = __DIR__ . '/' . \sprintf(self::TEST_FILE, $fileNumber);



        $file = $this->sniffFile($fileName, '7.3');

        $this->assertNoViolation($file, $line);
<?php     public function testNoFalsePositivesOnFile($fileNumber)

    {

        $fileName = __DIR__ . '/' . \sprintf(self::TEST_FILE, $fileNumber);



        $file = $this->sniffFile($fileName, '7.3');

        $this->assertNoViolation($file);
<?php     public function testNoViolationsInFileOnValidVersion($fileNumber)

    {

        $fileName = __DIR__ . '/' . \sprintf(self::TEST_FILE, $fileNumber);



        $file = $this->sniffFile($fileName, '7.4');

        $this->assertNoViolation($file);
<?php     public function testFopenMode($line, $mode, $errorVersion, $okVersion, $displayVersion = null)

    {

        $file  = $this->sniffFile(__FILE__, $errorVersion);

        $error = \sprintf(

            'Passing "%s" as the $mode to fopen() is not supported in PHP %s or lower.',

            $mode,

            isset($displayVersion) ? $displayVersion : $errorVersion

        );

        $this->assertError($file, $line, $error);



        $file = $this->sniffFile(__FILE__, $okVersion);
<?php     {

        $file  = $this->sniffFile(__FILE__, '5.4-7.0');

        $error = 'The default value of the %s parameter index for iconv_mime_encode() was changed from ISO-8859-1 to UTF-8 in PHP 5.6';

        $error = \sprintf($error, $missing);



        if ($type === 'error') {

            $this->assertError($file, $line, $error);
<?php     public function testNegativeStringOffset($line, $paramName, $functionName)

    {

        $file  = $this->sniffFile(__FILE__, '7.0');

        $error = \sprintf(

            'Negative string offsets were not supported for the $%1$s parameter in %2$s() in PHP 7.0 or lower.',

            $paramName,

            $functionName

        );

        $this->assertError($file, $line, $error);

    }
<?php     public function testNewPackFormat($line, $code, $errorVersion, $okVersion, $displayVersion = null)

    {

        $file  = $this->sniffFile(__FILE__, $errorVersion);

        $error = \sprintf(

            'Passing the $format(s) "%s" to pack() is not supported in PHP %s or lower.',

            $code,

            isset($displayVersion) ? $displayVersion : $errorVersion

        );

        $this->assertError($file, $line, $error);



        $file = $this->sniffFile(__FILE__, $okVersion);
<?php     public function testIndentedHeredocNowdoc($fileNumber, $line, $skipNoViolation = false)

    {

        $fileName = __DIR__ . '/' . \sprintf(self::TEST_FILE, $fileNumber);



        $file = $this->sniffFile($fileName, '7.2');

        $this->assertError($file, $line, 'Heredoc/nowdoc with an indented closing marker is not supported in PHP 7.2 or earlier.');
<?php     public function testCodeAfterHeredocNowdoc($fileNumber, $line, $skipNoViolation = false)

    {

        $fileName = __DIR__ . '/' . \sprintf(self::TEST_FILE, $fileNumber);



        $file = $this->sniffFile($fileName, '7.2');

        $this->assertError($file, $line, 'Having code - other than a semi-colon or new line - after the closing marker of a heredoc/nowdoc is not supported in PHP 7.2 or earlier.');
<?php     public function testForbiddenClosingMarkerInBody($line)

    {

        $fileName = __DIR__ . '/' . \sprintf(self::TEST_FILE, 2);



        $file = $this->sniffFile($fileName, '7.3');

        $this->assertError($file, $line, 'The body of a heredoc/nowdoc can not contain the heredoc/nowdoc closing marker as text at the start of a line since PHP 7.3.');
<?php     public function testNoFalsePositives()

    {

        $fileName = __DIR__ . '/' . \sprintf(self::TEST_FILE, 1);



        $file = $this->sniffFile($fileName, '7.2');

        $this->assertNoViolation($file);
<?php     public function testGetTestVersionInvalidRange($testVersion)

    {

        $message = \sprintf('Invalid range in testVersion setting: \'%s\'', $testVersion);

        $this->phpWarningTestHelper($message);



        $this->testGetTestVersion($testVersion, [null, null]);
<?php     public function testGetTestVersionInvalidVersion($testVersion)

    {

        $message = \sprintf('Invalid testVersion setting: \'%s\'', \trim($testVersion));

        $this->phpWarningTestHelper($message);



        $this->testGetTestVersion($testVersion, [null, null]);