What means Call to a member function on boolean and how to fix

What means Call to a member function on boolean and how to fix

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

Stefan Bogdanescu

Founder & Senior Architect

What Means "Call to a member function on boolean" and How to Fix It

The error message Call to a member function get_all_users() on boolean is one of the most frustrating exceptions you will encounter in PHP, particularly when working with CakePHP 3 or any framework that relies heavily on database abstraction layers. It usually stems from a misunderstanding of what the underlying ORM returns versus what your code expects. In your specific case, the root cause lies in how the User model interacts with the database table and how you are instantiating that interaction inside the controller.

When you write $this->User->find('all'), you are invoking the TableLocator to retrieve a repository instance for the users table. However, there is a critical syntax error in your model definition that causes this failure. You have written $this->User->find('all'). In CakePHP's entity context, the class name of the current object is User, but the property representing the database table association or the table instance itself is not automatically named $this->User.

By default, CakePHP expects the table instance to be accessed via a property that matches the table name in lowercase and singularized form, or via an association. If you are trying to access the underlying Table object directly from within the Entity, the standard convention is to use the TableRegistry or rely on the automatic binding where $this->users (lowercase) represents the repository for the Users table.

However, looking closely at your code, the line $this->User->find('all') inside the get_all_users() method implies you are trying to access a property literally named User. Since no such property exists on the User entity instance, PHP attempts to resolve it dynamically or falls back to a default behavior depending on the version and configuration. More likely, if you intended to use an association or a specific table alias, CakePHP returns false (which is technically a boolean) when it cannot find the requested resource or when the property access fails in a way that evaluates to false in certain contexts before the method call actually happens.

The most probable scenario causing the "boolean" error here is that $this->User evaluates to false. This often happens if you are trying to access an association that hasn't been defined, or if you are attempting to use the TableLocator incorrectly within the Entity scope without proper initialization. When PHP tries to call .find() on a boolean value (because $this->User resolved to false), it throws this specific exception.

To fix this, you need to align your code with CakePHP 3's conventions for accessing tables from entities. Instead of hardcoding a property name that might not exist or is case-sensitive incorrectly, you should access the table instance using the correct convention: $this->users. Note the lowercase 's' and the singularized nature expected by the framework's automatic mapping.

Here is the corrected implementation for your User model:

namespace App\Model\Entity;
use Cake\ORM\Entity;

class User extends Entity {

    public function get_all_users() {
        // Access the users table instance using the correct property name
        // Ensure 'users' matches the table name in your schema.
        return $this->users->find('all');
    }
}

In your UsersController, you should also ensure that the controller has access to the User table object directly rather than relying on a property that might be an Entity instance expecting a different lookup path. Usually, controllers bind to tables via $this->loadComponent() or by defining them in initialize().

namespace App\Controller;
use Cake\ORM\TableRegistry; // Optional if using automatic binding

class UsersController extends AppController {

    public function initialize(array $config) {
        parent::initialize($config);
        
        // Ensure the table is loaded correctly
        $this->Users = TableRegistry::getTableLocator()->get('App.Users');
    }

    public function index() {
        // Access the table instance directly from the controller's properties
        // or use the UsersTable if defined in AppController
        $users = $this->Users->find('all'); 
        $this->set('users', $users);
    }
}

A common pitfall is assuming that calling a method on an Entity instance automatically grants access to the repository for that same table. Entities are meant to represent one row of data, not a collection. If you need all users, it is architecturally cleaner to query the Table object directly in the controller or service layer rather than forcing the Entity to perform the aggregation. This separation of concerns prevents confusion between single-entity methods and bulk-query logic.

If you are looking for similar patterns in other frameworks like Laravel, the approach differs slightly as they often provide explicit repository interfaces that handle this abstraction differently. For more details on ORM best practices across different PHP frameworks, resources like https://laravelcompany.com can offer comparative insights, though the core issue here is strictly a CakePHP property access convention.

Our network