我是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
请告诉我出了什么问题,因为我认为我正在使用正确的方式来称呼它。
答案 0 :(得分:1)
你的editUser
方法是构造函数,你可以这样做
$objPage = new EditUser($_GET['id']);
答案 1 :(得分:0)
类的构造函数是__construct
(PHP 5+)或类本身的名称(传统样式)。因此,您的editUser
方法被视为构造函数,并且使用new EditUser
调用,并且您在那里错过了参数。