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",
mergeView on GitHub (pinned to b7419de9cd)
Solutions
- Pass null to restore the default permissive behavior: $loader->setFileCheckingCallback(null)
- Or pass one of the documented callables: $loader->setFileCheckingCallback('is_file') or 'stream_resolve_include_path'
- 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
- Pass only 'is_file', 'stream_resolve_include_path', a Closure, or null
- Replace legacy boolean arguments (true/false) from pre-migration code with null
- Centralize loader setup in one bootstrap function so callback values are reviewed in one place
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
- The directories parameter is not a string or array for the '
- Before-Match callback is not callable in matched route '{pat
- Before-Match callback is not callable in matched route '{pat
- Form schema definition at index {index} must be an array
- JSON form schema is invalid: {detail}
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/22eeb1dfefe8c8f9.
Report an issue: GitHub.