phalcon/cphalcon · error · Phalcon\Autoload\Exceptions\LoaderMethodNotCallable

The 'method' parameter must be either a callable or NULL

Error message

The 'method' parameter must be either a callable or NULL

What it means

Phalcon\Autoload\Loader::setFileCheckingCallback() accepts exactly two things: a callable that decides whether a file is loadable, or null to reset to the default that accepts every file. Any other value (a string that is not a callable function name, an array/object that is not callable, an integer...) throws LoaderMethodNotCallable before the callback is stored.

Source

Thrown at phalcon/Autoload/Loader.zep:410

     *
     * // Do not check file existence.
     * $loader->setFileCheckingCallback(null);
     * ```
     *
     * @param callable|string|null $method
     *
     * @throws Exception
     */
    public function setFileCheckingCallback(var method = null) -> <static>
    {
        if (true === is_callable(method)) {
            let this->fileCheckingCallback = method;
        } elseif (null === method) {
            let this->fileCheckingCallback = function (file) {
                return true;
            };
        } else {
            throw new LoaderMethodNotCallable();
        }

        return this;
    }

    /**
     * Registers files that are "non-classes" hence need a "require". This is
     * very useful for including files that only have functions
     *
     * @param autoload_strings $files
     */
    public function setFiles(array files, bool merge = false) -> <static>
    {
        return this->addToCollection(
            files,
            "files",
            "addFile",
            merge

View on GitHub (pinned to b7419de9cd)

Solutions

  1. Pass null to restore the default permissive behavior: $loader->setFileCheckingCallback(null)
  2. Or pass one of the documented callables: $loader->setFileCheckingCallback('is_file') or 'stream_resolve_include_path'
  3. Replace legacy boolean usage: old setFileCheckingCallback(true) becomes null; and make sure any custom value is a valid callable (Closure, ['Obj','method'], 'functionName')

Example fix

// before (legacy boolean style)
$loader->setFileCheckingCallback(true);

// after
$loader->setFileCheckingCallback('is_file');
// or simply omit it / pass null for the default
Defensive patterns

Strategy: type-guard

Validate before calling

if ($callback !== null && !is_callable($callback)) {
    throw new InvalidArgumentException('setFileCheckingCallback expects a callable or null');
}

Type guard

function isValidFileCheckingCallback($value): bool
{
    return $value === null || is_callable($value);
}

Prevention

When it happens

Trigger: $loader->setFileCheckingCallback('file_exists') (not callable as invoked - the documented values are 'is_file' or 'stream_resolve_include_path'); passing a method name of a non-existent function; passing 1/true/[] as a pseudo-truthy flag; passing an object without __invoke.

Common situations: Upgrading from old Phalcon versions where file-checking was a boolean (setFileCheckingCallback(true)) - the boolean API is gone and true now throws; passing a disabled/renamed function name; copy-pasting a callback name from outdated docs.

Related errors


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/22eeb1dfefe8c8f9. Report an issue: GitHub.