{"record":{"id":"cdfcdc8d1227f03e","repo":"phalcon/cphalcon","slug":"the-static-method-method-in-classname-requ","errorCode":null,"errorMessage":"The static method '{method}' in '{className}' requires one argument","messagePattern":"The static method '(.+?)' in '(.+?)' requires one argument","errorType":"exception","errorClass":"Phalcon\\Mvc\\Model\\Exceptions\\StaticMethodRequiresOneArgument","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model.zep","lineNumber":5068,"sourceCode":"        /**\n         * Check if the method starts with \"count\"\n         */\n        elseif starts_with(method, \"countBy\") {\n            let type = \"count\",\n                extraMethod = substr(method, 7);\n        }\n\n        /**\n         * The called class is the model\n         */\n        let modelName = get_called_class();\n\n        if !extraMethod {\n            return false;\n        }\n\n        if unlikely !array_key_exists(0, arguments) {\n            throw new StaticMethodRequiresOneArgument(method, get_called_class());\n        }\n\n        let model    = create_instance(modelName),\n            metaData = model->getModelsMetaData();\n\n        /**\n         * Get the attributes\n         */\n        let attributes = metaData->getReverseColumnMap(model);\n\n        if typeof attributes !== \"array\" {\n            let attributes = metaData->getDataTypes(model);\n        }\n\n        /**\n         * Check if the extra-method is an attribute\n         */\n        if isset attributes[extraMethod] {","sourceCodeStart":5050,"sourceCodeEnd":5086,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model.zep#L5050-L5086","documentation":"Thrown by Model::invokeFinder() (phalcon/Mvc/Model.zep:5068), the engine behind magic static finders: a method like findFirstBy..., findBy... or countBy... was called with an empty argument list. The exception class is Phalcon\\Mvc\\Model\\Exceptions\\StaticMethodRequiresOneArgument. The first argument is the value bound to the WHERE condition, so it cannot be omitted.","triggerScenarios":"Calling Invoices::findFirstByStatus() with no parameters; forwarding a finder call with call_user_func_array([Invoices::class, 'findByStatus']) and an empty array; refactoring a method signature and dropping the argument at the call site.","commonSituations":"Refactor typos where the value variable is removed; dynamic finder invocation from user input where the parameter key is missing; copy-pasted example code without arguments.","solutions":["Pass the value as the first argument: Invoices::findFirstByStatus('pending')","For dynamic calls, check the arguments array is non-empty before invoking","Pass null explicitly to search for NULL: Invoices::findFirstByStatus(null) generates IS NULL"],"exampleFix":"// before\n$invoice = Invoices::findFirstByStatus(); // StaticMethodRequiresOneArgument\n\n// after\n$invoice = Invoices::findFirstByStatus('pending');\n// or for NULL lookup:\n$invoice = Invoices::findFirstByStatus(null);","handlingStrategy":"type-guard","validationCode":"if (func_num_args() < 1) {\n    throw new InvalidArgumentException('finder value required');\n}\n$value = $args[0] ?? null;\n$invoice = Invoices::findFirstByStatus($value);","typeGuard":"// guard before a dynamically built magic finder call\nfunction assertFinderArgs(string $method, array $args): void\n{\n    if (preg_match('/^(findFirstBy|findBy|countBy)/', $method) && !array_key_exists(0, $args)) {\n        throw new InvalidArgumentException(\"{$method} requires one argument\");\n    }\n}","tryCatchPattern":"try {\n    $invoice = Invoices::findFirstByStatus($status);\n} catch (\\Phalcon\\Mvc\\Model\\Exceptions\\StaticMethodRequiresOneArgument $e) {\n    // programming error: default the value and log it\n    $status = $status ?? 'pending';\n    $invoice = Invoices::findFirstByStatus($status);\n}","preventionTips":["Always pass the value, even null, when you want an IS NULL lookup","Static-analyze call sites: magic finders with zero args are detectable with custom PHPStan rules","Prefer explicit find(['conditions' => ...]) for dynamic code paths"],"tags":["phalcon","orm","magic-finder","static-call","argument"],"backgroundTag":"missing-required-argument","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}