{"record":{"id":"428e77159722ded9","repo":"sebastianbergmann/phpunit","slug":"s-is-not-a-valid-phpt-section","errorCode":null,"errorMessage":"--%s-- is not a valid PHPT section","messagePattern":"--(.+?)-- is not a valid PHPT section","errorType":"exception","errorClass":"UnknownPhptSectionException","httpStatus":null,"severity":"error","filePath":"src/Runner/Phpt/Parser.php","lineNumber":129,"sourceCode":"\n        $lines = @file($phptFile);\n\n        if ($lines === false) {\n            throw new CannotLoadPhptFileException;\n        }\n\n        $lineNr = 0;\n\n        foreach ($lines as $line) {\n            $lineNr++;\n\n            if (preg_match('/^--([_A-Z]+)--/', $line, $result) === 1) {\n                $section = $result[1];\n\n                if (!in_array($section, self::SUPPORTED_SECTIONS, true) &&\n                    !in_array($section, self::UNSUPPORTED_SECTIONS, true) &&\n                    !in_array($section, self::IGNORED_SECTIONS, true)) {\n                    throw new UnknownPhptSectionException($section);\n                }\n\n                if (isset($sections[$section])) {\n                    throw new DuplicatePhptSectionException($section);\n                }\n\n                $sections[$section]             = '';\n                $sections[$section . '_offset'] = (string) $lineNr;\n\n                continue;\n            }\n\n            if ($section === '') {\n                throw new InvalidPhptFileException(\n                    sprintf(\n                        'PHPT file must not contain text before its first section (line %d)',\n                        $lineNr,\n                    ),","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/sebastianbergmann/phpunit/blob/f123cdb2a2d49f15025794166cfed8bda8627dd2/src/Runner/Phpt/Parser.php#L111-L147","documentation":"Phpt\\Parser::parse() scans a .phpt file line by line; any line matching /^--([_A-Z]+)--/ is treated as a section header. When the captured name is in none of the SUPPORTED_SECTIONS, UNSUPPORTED_SECTIONS or IGNORED_SECTIONS constants, UnknownPhptSectionException('--%s-- is not a valid PHPT section') is thrown and the file is rejected before it can run. PHPUnit only understands its documented PHPT section set.","triggerScenarios":"A .phpt file containing a section header PHPUnit does not know at all: a typo such as --EXCEPT-- instead of --EXPECT--, a custom section like --MY_SECTION--, or a section introduced by a newer php run-tests.php than this PHPUnit version recognizes.","commonSituations":"Copying PHPT tests from php/php-src or PECL into a PHPUnit-driven suite; typos while hand-writing section headers; using a newer PHP run-tests format on an older PHPUnit.","solutions":["Fix the header so it matches a section PHPUnit knows: code sections FILE, FILEEOF, FILE_EXTERNAL; expectations EXPECT, EXPECT_EXTERNAL, EXPECTF, EXPECTF_EXTERNAL, EXPECTREGEX, EXPECTREGEX_EXTERNAL; plus TEST, INI, ENV, SKIPIF, XFAIL, CLEAN, STDIN, ARGS.","Remove the custom section if it carries no meaning for PHPUnit; free-form description text belongs in --TEST-- or --DESCRIPTION-- (the latter is ignored).","Upgrade PHPUnit — newer releases may recognize sections older versions reject as unknown."],"exampleFix":"-- before\n--FILE--\necho 'Hello';\n--EXCEPT--\nHello\n\n-- after\n--FILE--\necho 'Hello';\n--EXPECT--\nHello","handlingStrategy":"validation","validationCode":"function assertKnownPhptSections(string $phptFile): void\n{\n    $known = ['TEST','FILE','FILEEOF','FILE_EXTERNAL','EXPECT','EXPECT_EXTERNAL',\n        'EXPECTF','EXPECTF_EXTERNAL','EXPECTREGEX','EXPECTREGEX_EXTERNAL',\n        'INI','ENV','SKIPIF','XFAIL','CLEAN','STDIN','ARGS',\n        'CGI','COOKIE','DEFLATE_POST','EXPECTHEADERS','EXTENSIONS','GET',\n        'GZIP_POST','HEADERS','PHPDBG','POST','POST_RAW','PUT','REDIRECTTEST','REQUEST',\n        'CAPTURE_STDIO','CONFLICTS','CREDITS','DESCRIPTION','FLAKY',\n        'WHITESPACE_SENSITIVE','XLEAK'];\n\n    foreach (file($phptFile) as $i => $line) {\n        if (preg_match('/^--([_A-Z]+)--/', $line, $m) === 1 && !in_array($m[1], $known, true)) {\n            throw new RuntimeException(sprintf('Unknown section --%s-- at line %d', $m[1], $i + 1));\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    $sections = (new \\PHPUnit\\Runner\\Phpt\\Parser())->parse($phptFile);\n} catch (\\PHPUnit\\Runner\\Phpt\\UnknownPhptSectionException $e) {\n    // report the offending section name ($e->getMessage()) and skip/repair the file\n}","preventionTips":["Run a PHPT lint step in CI that checks every header against the supported/unsupported/ignored lists before executing the suite.","Create new .phpt files from a tested template containing only known sections.","After copying upstream PHPT tests, diff their section headers against PHPUnit's documented set."],"tags":["phpunit","phpt","parser","section-header","typo"],"backgroundTag":"unknown-file-section","analyzedSha":"f123cdb2a2d49f15025794166cfed8bda8627dd2","analyzedAt":"2026-08-23T01:20:58.058Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}