PhpStorm Missing property's type declaration on protected property
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Resolving PhpStorm Warnings: Missing Property Type Declarations on Protected Properties in Inheritance
As senior developers working within large frameworks like Laravel, we constantly deal with codebases that extend vendor classes. While this inheritance pattern is powerful, it often creates friction when static analysis tools (like those built into PhpStorm) are applied. Today, we're diving into a very specific, yet common, scenario: encountering warnings from PhpStorm regarding missing type declarations on protected properties inherited from base classes.
This post will dissect why this happens and provide practical solutions so you can silence these warnings while maintaining clean, modern PHP code.
The Scenario: Inheritance and Static Analysis Conflict
You are working within the Laravel ecosystem, extending a class like Illuminate\Foundation\Console\Kernel. Within that parent class, properties such as $commands might be declared without explicit type hints:
// Inside Illuminate\Foundation\Console\Kernel (Vendor Code)
protected $commands = [
// commands definition...
];
When you extend this class in your application code, PhpStorm performs deep static analysis. Because the parent property $commands lacks a declared type hint (array, string, etc.), PhpStorm flags it as "Missing property's type declaration." This is not necessarily a runtime error—PHP will happily accept the definition—but it signals a potential lack of contract definition, which violates the principles of modern static typing.
The conflict arises because your child class attempts to utilize or interact with this inherited property, and the IDE insists that all properties should adhere to strict type definitions for maximum safety and maintainability.
Why This Matters: The Importance of Type Safety
In modern PHP development, explicit type declarations are crucial. They allow static analysis tools and IDEs to understand the exact shape of your data before execution. When dealing with framework components, even if you cannot change the vendor code, ensuring your own implementation adheres to best practices is vital for long-term maintainability.
Laravel emphasizes robust, organized code, and adhering to strict typing helps enforce this quality across the entire application. For instance, understanding object contracts correctly is key when building custom service providers or console commands, ensuring that framework expectations are met while still allowing necessary flexibility in inheritance.
Solutions: How to Resolve the PhpStorm Warning
Since we cannot directly edit the vendor files, we must address this within our own class definition using appropriate PHP mechanisms. Here are the most effective strategies:
1. Explicitly Type the Property Locally (The Recommended Approach)
The cleanest solution is to redefine or explicitly type the property in your child class (App\Console\Kernel). This tells PhpStorm exactly what the property holds, satisfying its static analysis requirements without modifying the parent class.
If you know $commands should always be an array of strings, declare it as such:
namespace App\Console;
use Illuminate\Foundation\Console\Kernel;
class Kernel extends Kernel
{
/**
* @var array<string>
*/
protected $commands = []; // Explicitly typed using PHPDoc for clarity
// Alternatively, use native type hinting if PHP version allows:
// protected array $commands = [];
// ... rest of your class methods
}
Using a docblock (@var) clearly communicates the expected type to IDEs and other developers. This satisfies PhpStorm's requirement for type information while respecting the structure provided by the base class.
2. Utilizing @var for Clarity (The Pragmatic Approach)
If you prefer not to use native scalar type hints (perhaps due to compatibility concerns or complexity), using the @var annotation in PHPDoc comments is an excellent, robust alternative. This method clearly documents the expected type for the property, which static analyzers respect fully.
3. Understanding Framework Conventions
In many cases, framework properties are intentionally left loosely typed in base classes to allow maximum flexibility for various implementations (e.g., different console commands). If you find yourself constantly fighting this, it might be worth reviewing if there is a more appropriate abstraction layer or interface within Laravel that handles command definition separately, rather than relying solely on direct property inheritance for this specific data.
Conclusion
Encountering static analysis warnings in inherited code is a common hurdle when working with large frameworks. The key takeaway is to treat these IDE warnings not as errors, but as prompts to enforce better contracts within your own code. By strategically applying native type hints or comprehensive PHPDoc annotations, you can satisfy PhpStorm's demands for clarity while smoothly inheriting functionality from the base classes. Keep focusing on writing self-documenting, strongly-typed code—it pays dividends in debugging time and overall project quality.