Reference

Diagnostics

Every code the compiler can report, grouped by family, with what each family covers.

Every diagnostic carries a stable code. A code never changes meaning between releases, so it is the thing to search for, to paste into an issue, and to branch on in tooling that reads --format=json. The families below are grouped by the first digit of the code.

Console output for a diagnostic always has the same shape: severity and code, a title, a one-sentence message, the location as file:line:column, a source frame with the problem underlined, any related locations, and a help line. The CLI shows a complete example.

Most codes are errors and make check and build exit with status 1. The few warnings are marked below; they are reported but do not fail the command on their own.

Project and configuration (P0xxx)

Reported before any source is analysed: a missing or invalid ppphp.json, unsafe or overlapping paths, an unreadable selection, or an invocation the command does not support.

Code Title
P0001 Project Configuration Not Found
P0002 Project Configuration Is Not Readable
P0003 Invalid Project Configuration JSON
P0004 Unknown Configuration Property
P0005 Missing Configuration Property
P0006 Invalid Configuration Property Type
P0007 Unsupported Target PHP Version
P0008 Unsafe Project Path
P0009 Project Configuration Already Exists
P0011 Project Path Does Not Exist
P0012 Project Path Is Not A Directory
P0013 Configured Paths Overlap
P0014 Source Path Does Not Exist
P0015 Source Path Is Not A Directory
P0016 File Is Outside Project Root
P0017 Project Cleanup Failed
P0018 Input Path Does Not Exist
P0019 Input Path Is Not A File
P0020 Invalid Output Format
P0021 Project Initialization Failed
P0022 Invalid Invocation
P0023 Project Source Discovery Failed
P0024 Selected Path Excluded
P0025 Selected Path Not Readable

Syntax (P1xxx)

The file could not be parsed as PHP or as ++PHP, or is not a kind of file the compiler accepts.

Code Title
P1001 Invalid PHP Syntax
P1002 Explicit Source File Is Required
P1004 Unsupported Source File
P1005 Selected Path Is Outside Configured Source Roots
P1006 Source File Not Readable
P1008 Invalid Extension Syntax
P1009 Unsupported Extension Syntax
P1010 Extension Normalization Failed
P1011 Missing PHP Opening Tag

Variables and types (P2xxx)

Check the type of the value at the highlighted location against the variable, parameter, property, or return type it must satisfy. For an unknown member, check its spelling and the object's type. Typed locals and Strict types show the declaration rules. P2099 reports a type-checking problem without a more specific code; its message identifies what needs fixing.

Code Title
P2002 Assignment Cannot Declare Variable
P2003 Local Variable Is Not Declared
P2004 Duplicate Local Declaration
P2005 Readonly Local Cannot Be Reassigned
P2006 Readonly Local Cannot Be Mutated
P2007 Readonly Local Cannot Be Referenced
P2008 Initializer Is Not Assignable To Declared Type
P2009 Assignment Is Not Assignable To Declared Type
P2010 Unsupported Local Binding Position
P2011 Missing Parameter Type
P2012 Missing Return Type
P2013 Missing Property Type
P2014 Implicit Mixed Is Not Allowed
P2015 Argument Type Does Not Match
P2016 Return Type Does Not Match
P2017 Not All Paths Return A Value
P2018 Method Does Not Exist
P2019 Property Does Not Exist
P2020 Type Does Not Exist
P2021 Function Does Not Exist
P2022 Dynamic Property Is Not Allowed
P2023 Unsafe Dynamic Construct
P2024 Property Type Does Not Match
P2025 Null Is Not Assignable
P2026 Loop Binding Type Does Not Match
P2027 Local Variable May Be Uninitialized
P2028 Readonly Foreach Binding Not Supported
P2029 Multiple Typed For Initializers Are Not Supported
P2030 Invalid Composite Type
P2031 Intersection Type Is Not Satisfied
P2033 Strict Types Cannot Be Disabled
P2034 Duplicate Project Declaration
P2035 Argument Count Does Not Match
P2036 Named Argument Does Not Exist
P2037 Duplicate Named Argument
P2038 Positional Argument After Named Argument
P2039 Argument Must Be Referenceable
P2040 Static Member Access Is Invalid
P2041 Instance Member Access Is Invalid
P2042 Member Read Is Not Allowed
P2043 Member Write Is Not Allowed
P2044 Property May Be Uninitialized
P2045 Class Constant Does Not Exist
P2046 Property Is Never Read (warning)
P2099 Static Analysis Error

Generics and typed arrays (P3xxx)

Check that you supplied the required type arguments and that each satisfies its declared bound. For typed arrays, check both the key and the value being added. See Generics and Typed arrays for examples.

Code Title
P3002 Duplicate Type Parameter
P3003 Unknown Type Parameter
P3004 Generic Type Argument Count Does Not Match
P3005 Type Argument Does Not Satisfy Bound
P3006 Generic Type Arguments Are Required
P3007 Type Is Not Generic
P3008 Generic Runtime Operation Is Not Allowed
P3009 Static Member Cannot Use Class Type Parameter
P3010 Generic Documentation Conflicts With Native Syntax
P3011 Invalid Generic Bound
P3012 Typed Array Key Type Is Invalid
P3013 Typed Array Value Type Does Not Match
P3014 Typed Array Key Type Does Not Match
P3015 Operation Would Break List Shape
P3016 Generic Type Is Invariant
P3099 Generic Static Analysis Error

Checked errors (P4xxx)

Catch the named error or add it to your function's throws clause when the caller should handle it. At file scope, catch it before it leaves the file. See Checked errors for examples of handling and propagating errors.

Code Title
P4002 Error Type Is Not Throwable
P4003 Checked Error Is Not Handled
P4004 Checked Error Declaration Is Not Covariant
P4005 Unchecked Call Boundary (warning)
P4006 Native Throws Clause Is Required
P4007 Throws Documentation Conflicts With Native Clause
P4008 Checked Error Cannot Escape File Scope
P4009 Checked Error Cannot Escape Anonymous Callable
P4010 Checked Error Cannot Escape Destructor
P4011 Duplicate Error Declaration
P4012 Caught Error Is Never Thrown
P4013 Error Catch Is Unreachable

when expressions (P5xxx)

Make sure each branch returns a value compatible with the destination type or throws, and include a final else. See when expressions for supported uses and branch rules.

Code Title
P5002 When Branch Does Not Produce A Value
P5003 When Result Requires A Value
P5004 When Result Type Does Not Match
P5005 When Position Is Not Supported
P5006 When Control Transfer Is Not Allowed
P5007 When Yield Is Not Allowed
P5008 When Goto Is Not Allowed
P5009 When By-Reference Argument Is Not Allowed
P5010 When Branch Could Not Be Parsed

PHP and Composer interoperability (P6xxx)

Composer configuration and autoload mappings, installed dependencies, stubs, and the bundled analysis pass.

Code Title
P6001 Invalid Composer Configuration
P6002 Invalid Composer Autoload Mapping
P6003 Invalid Installed Composer Metadata
P6004 Configured Stub Path Is Invalid
P6005 Static Analysis Failed
P6006 Static Analysis Result Is Invalid
P6007 Analysis Workspace Could Not Be Prepared
P6008 Composer Autoload Does Not Target Build Output (warning)
P6009 Composer Autoload Mapping Cannot Be Projected
P6010 Composer Configuration Could Not Be Updated
P6011 Composer Runtime Mapping Conflicts With Build Output
P6012 Stub Contract Conflict
P6013 Composer Dependency Index Limit Exceeded
P6014 Composer Dependency Source Not Readable
P6015 Composer Dependency Declaration Invalid
P6016 PHP Signature Package Invalid
P6017 Declaration Conflicts With PHP Platform
P6018 Dependency Declaration Context Unavailable
P6019 Portable Dependency Index Invalid
P6020 Dependency Declaration Ambiguous
P6021 Dependency Source Path Unsafe

Generated PHP (P7xxx)

These errors occur while writing or validating generated PHP. Check the named output path, file permissions, and whether another build is running. Do not edit generated files to fix a source error; correct the .ppphp source and rebuild. If the compiler produces invalid PHP from valid source, report it with a small reproduction.

Code Title
P7002 Generated PHP Output Path Collision
P7003 Generated PHP Is Invalid
P7004 Build Manifest Is Invalid
P7005 Build Could Not Be Staged
P7006 Build Could Not Be Committed
P7007 Previous Build Could Not Be Restored
P7008 Output Path Is Reserved
P7009 Build Is Already In Progress
P7010 Source Map Could Not Be Written
P7011 Build Manifest Does Not Match Configuration
P7012 Build Output Has Been Modified
P7013 Previous Build Backup Could Not Be Removed (warning)
P7014 Build Transaction Could Not Be Recovered
P7015 PHP Output Validation Failed

Compiler failures (P9xxx)

A guarded failure inside the compiler itself. Report it with the --debug output.

Code Title
P9001 Internal Compiler Error