0

我是 php 新手,我正在尝试在 php 5 中工作,所以我调用了一个参数化函数,但它给了我异常“警告:缺少参数 1”这是我的课程

class EditUser extends DBConn
{

private $id;
function editUser($id)
{
    $this->id = $id;
    echo $id;
    die;

    $rows =array();
    self::Set_DBConni();
    $mysqli = self::get_Conn();
    $result = $mysqli->query("SELECT * FROM users where id ='".$id."' ");

        while($row = $result->fetch_row())
        {
            $rows[] = $row;

        }


        return $rows;

        /* free result set */
        $result->close();

        /* close connection */
        $mysqli->close();

}


 }

这就是我所说的

include_once('include/classes/edituser.php'); 

$objPage = new EditUser();

$objPage->editUser($_GET['id']);

但它向我显示了警告,那就是

Warning: Missing argument 1 for EditUser::editUser(), called in E:\xampp\htdocs\WaleedWork\claremont\admin\edit_user.php on line 45 and defined in E:\xampp\htdocs\WaleedWork\claremont\admin\include\classes\edituser.php on line 8

Notice: Undefined variable: id in E:\xampp\htdocs\WaleedWork\claremont\admin\include\classes\edituser.php on line 10

Notice: Undefined variable: id in E:\xampp\htdocs\WaleedWork\claremont\admin\include\classes\edituser.php on line 11

请告诉我出了什么问题,因为我认为我正在使用正确的方式来调用它。

4

2 回答 2

1

你的editUser方法是一个构造函数,你可以这样做

$objPage = new EditUser($_GET['id']);

于 2013-10-29T09:49:31.790 回答
0

类的构造函数是__construct(PHP 5+)或类本身的名称(传统风格)。因此,您的editUser方法被视为构造函数并被调用new EditUser,并且您缺少那里的参数。

于 2013-10-29T09:59:45.337 回答