Expected type 'object'. Found 'void'.intelephense(1006) Issue in PHP MVC project

Expected type 'object'. Found 'void'.intelephense(1006) Issue in PHP MVC project

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Expected type 'object'. Found 'void'.intelephense(1006) Issue in PHP MVC project

When you see the Expected type 'object'. Found 'void'.intelephense(1006) error in an IDE like PhpStorm or VS Code, it usually points to a fundamental misunderstanding of how PHP handles variable scopes and class definitions. The specific issue stems from the fact that $user is not treated as an object instance within the scope where you are trying to access its properties, despite looking like it should be one.

In your Home controller, you have defined a method named model:

public function model($model) {
    echo $model;
}

This is the primary culprit. In PHP, methods are resolved by name at runtime. When you execute $this->model('User'), the language looks for a method called model inside your Home class (or inherited from Controller). Because both classes define a method with that exact name, and the one in Home is defined after or alongside the logic trying to use it, you are triggering the local version of the method.

The local model method in your Home class contains only echo $model; and lacks a return statement. In PHP, any function that does not explicitly return a value returns null. However, static analysis tools like Intelephense are often stricter or rely on type hints to determine intent. If the method signature implies it should return something (or if you are using strict typing), but the implementation provides no return statement, the tool effectively sees this as returning void (or null).

Consequently, when you run $user = $this->model('User');, the variable $user is assigned either null or nothing. The subsequent line, $user->name = $name;, attempts to access the name property of that result. Since the result is not an object (it is null/void), the IDE flags an error: "Expected type 'object', found 'void'".

To resolve this, you must ensure that the method intended to instantiate the model is actually being called and that it returns the new instance. Your parent Controller class has the correct logic:

public function model($model) {
    require_once '../app/models/' . $model . '.php';
    return new $model();
}

This method correctly uses require_once to load the file and returns a new instance of the class. However, because your child class Home overrides this method without a return statement, it shadows the parent implementation.

The fix is simple: remove or rename the conflicting model method in your Home class if you do not need specific custom logic there. If you intended to override the behavior, you must ensure it still returns the instantiated object:

public function model($model) {
    // Logic to load and instantiate the model
    require_once '../app/models/' . $model . '.php';
    return new $model(); // Essential return statement
}

Additionally, consider your User class implementation. While valid for a simple script, MVC architecture often benefits from constructor injection or dependency management rather than direct instantiation inside controllers. Directly calling require_once and new inside every controller method can lead to tight coupling and makes testing difficult. A more scalable approach involves defining a base model class with common traits (like database connections) in your app/models directory, then extending that base class for specific entities like User.

The error message is Intelephense's way of telling you that the variable $user does not hold an object reference in its current scope. By ensuring your method explicitly returns the new instance and avoiding accidental method shadowing that strips away return values, the type mismatch disappears, and your MVC structure becomes semantically correct.

Our network