{"record":{"id":"302d09ced41bd310","repo":"phalcon/cphalcon","slug":"class-classname-does-not-have-a-method-name","errorCode":null,"errorMessage":"Class '{className}' does not have a method '{name}'","messagePattern":"Class '(.+?)' does not have a method '(.+?)'","errorType":"exception","errorClass":"Phalcon\\DataMapper\\Pdo\\Exception\\UnknownDriverMethod","httpStatus":null,"severity":"error","filePath":"phalcon/DataMapper/Pdo/Connection/AbstractConnection.zep","lineNumber":88,"sourceCode":"     *\n     * @param string $name\n     * @param array  $arguments\n     *\n     * @return mixed\n     * @throws BadMethodCallException\n     */\n    public function __call(var name, array arguments)\n    {\n        var className, message;\n\n        this->connect();\n\n        if !method_exists(this->pdo, name) {\n            let className = get_class(this),\n                message   = \"Class '\" . className\n                          . \"' does not have a method '\" . name . \"'\";\n\n            throw new UnknownDriverMethod(message);\n        }\n\n        return call_user_func_array(\n            [\n                this->pdo,\n                name\n            ],\n            arguments\n        );\n    }\n\n    /**\n     * Begins a transaction. If the profiler is enabled, the operation will\n     * be recorded.\n     *\n     * @return bool\n     */\n    public function beginTransaction() -> bool","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/DataMapper/Pdo/Connection/AbstractConnection.zep#L70-L106","documentation":"The connection classes forward unknown method calls through __call() to the underlying \\PDO instance. If method_exists() on the PDO object is false, UnknownDriverMethod is thrown: you called a method that is neither defined on the connection class itself nor a real PDO method.","triggerScenarios":"Calling PDOStatement-level methods on the connection (fetchObject, execute, bindParam) instead of on the statement; habits from other DB libraries (Doctrine DBAL, mysqli) like ->executeQuery(); typo'd method names (->querry()); helper methods you expected the wrapper to provide.","commonSituations":"Mixing API styles when migrating from another DBAL; calling data-access helpers that live on the statement, not the connection; stale method names after upgrading.","solutions":["Use the connection's own fetch* helpers (fetchOne, fetchAll, etc.) or query()/prepare() and call statement methods on the returned PDOStatement","Check the PHP PDO method list — only PDO methods can be forwarded","Fix typos; the message names the class and the missing method","No special setup is needed — the connection connects automatically before forwarding valid calls"],"exampleFix":"// before\n$user = $connection->fetchObject('User'); // not a Connection or PDO method\n\n// after\n$stmt = $connection->query('SELECT * FROM users WHERE id = 1');\n$user = $stmt->fetchObject('User');","handlingStrategy":"validation","validationCode":"$method = 'fetchObject';\nif (!method_exists($connection, $method) && !method_exists(\\PDO::class, $method)) {\n    throw new BadMethodCallException(\n        get_class($connection) . \" has no method '{$method}' (and PDO does not either)\"\n    );\n}\nreturn $connection->{$method}(...$args);","typeGuard":null,"tryCatchPattern":"use Phalcon\\DataMapper\\Pdo\\Exception\\UnknownDriverMethod;\n\ntry {\n    $result = $connection->{$name}(...$args);\n} catch (UnknownDriverMethod $e) {\n    throw new BadMethodCallException('Invalid DB call: ' . $e->getMessage(), 0, $e);\n}","preventionTips":["Call statement methods (fetchObject, execute, bind*) on the PDOStatement, not on the connection","Use the connection's fetch* helpers for reading data instead of raw PDO forwarding","Avoid dynamic method dispatch on the connection unless you validate against PDO's method list first"],"tags":["pdo","database","undefined-method","magic-methods","phalcon"],"backgroundTag":"undefined-method","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}