catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Action() function can't support for transfer external parameter into it #803

Closed cw1427 closed 5 years ago

cw1427 commented 5 years ago

Describe the bug Action() function can't support for transfer external parameter into it. from the source, we could know it only accept the db instance but can't accept the other parameters public function action($actions) { if (is_callable($actions)) { $this->pdo->beginTransaction();

        try {
            $result = $actions($this);

            if ($result === false)
            {
                $this->pdo->rollBack();
            }
            else
            {
                $this->pdo->commit();
            }
        }
        catch (Exception $e) {
            $this->pdo->rollBack();

            throw $e;
        }

        return $result;
    }

    return false;
}

Information

Detail Code The detail code causes the problem.

Expected output A clear and concise description of what output you expected.

catfan commented 5 years ago

You can use use keyword for closure function call.

http://php.net/manual/en/functions.anonymous.php

Or variable scope

http://php.net/manual/en/language.variables.scope.php

Up to your project.