Error Missing argument 1 for user::__construct()?

2019-09-14 01:55发布

I am recieving folloing error for my code. Please help me out guys.

Warning: Missing argument 1 for user::__construct(), called in C:\wamp\www\oop\index.php on line 8 and defined in C:\wamp\www\oop\loader\user.php on line 5

and this one

Notice: Undefined variable: Cr in C:\wamp\www\oop\loader\user.php on line 7

Index.php

<?php
function __autoload($class)
{
    include "Loader/$class.php";
} 
$user1 = new user;
echo $user1->userCreate("Blue");


?>

user.php

<?php

    class user {
        protected $userOne;
        public function __construct($Cr)
        {
            $this->userOne = $Cr;
        }
        public function userCreate() {
            return $this->userOne." User Created ";

        }
        public function userDelete() {
            return $this->userOne."user deleted";
        }

    }

?>

标签: php oop
1条回答
狗以群分
2楼-- · 2019-09-14 02:13

You are passing parameters to wrong methods.
userCreate doesn't need a parameter but __construct does need one.

See below

$user1 = new user("Blue");
echo $user1->userCreate();
查看更多
登录 后发表回答