pass a db connexion instance to other classes php : <p>i am trying to make a registration system using PHP OOP but im getting this errors when i excute it</p>

<blockquote>
  <p>Notice: Undefined variable: connect in C:\wamp64\www\news\classes\user.php on line 14</p>
  
  <p>Fatal error: Call to a member function prepare() on null in C:\wamp64\www\news\classes\user.php on line 14</p>
</blockquote>

<p>i beleive that my problem is that my calsse can't get the db connection instance even im passing it on intiation. i have 2 classes and a registration page
my first class is dbconnect.php</p>

<pre><code>&lt;?php

    include "./config.php";

    class dbconnect{

        public  function __construct(){
            try {
                $conect = new PDO('mysql:host='.SERVER.'; dbname='.DATABASE, USERNAME, PASSWORD); 
                $conect-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                return $conect;

            }
        catch(PDOException $e)
                {
                echo "Connection failed: " . $e-&gt;getMessage();
            }
        }

    }


?&gt;
</code></pre>

<p>my second class is user.php</p>

<pre><code>&lt;?php

    class user{
        public  $username;
        public  $connect;

            function __construct($username,$connect){
                $this-&gt;username=$username;
                $this-&gt;connect=$connect;
            }

            protected function user_exist(){
                $request="SELECT * FROM `users` where username='".$this-&gt;username."'";
                $sql=$connect-&gt;prepare($request);
                $sql-&gt;execute();
                $results = $sql-&gt;fetch(PDO::FETCH_ASSOC);

                if(is_array($results)){
                    //echo "utilisateur exist";
                    return true;
                }
                else{
                    //echo "utilisateur n'existe pas";
                    return false;
                }           
            }
            public function register($firstname,$lastname,$email,$user,$password){
                if(!($this-&gt;user_exist())){
                    $request="INSERT INTO USERS (nom,prenom,email,user,pass,role,statut,date ) VALUES (:firstname, :lastname, :email, :username, :password, :role,:staut, :now())";
                    $sql = $connect-&gt;prepare($request);
                    $sql-&gt;bindParam(':fistname', $firstname);
                    $sql-&gt;bindParam(':lastname', $lastname);
                    $sql-&gt;bindParam(':email', $email);
                    $sql-&gt;bindParam(':username', $username);
                    $sql-&gt;bindParam(':password', $password);
                    $sql-&gt;bindParam(':role', 'subscriber');
                    $sql-&gt;bindParam(':statut', 'waiting for validation');
                    //$sql-&gt;bindParam(':date', $date);
                    try{
                        $sql-&gt;execute();
                    }
                    catch(Exception $e){
                        if ($e-&gt;getCode() == 1062) {
                            echo $e;
                        } else {
                            throw $e;
                        }
                    }

                }
            }


    } 

?&gt;
</code></pre>

<p>and then my registration page</p>

<pre><code>&lt;?php
    include "classes/dbconnect.php";
    include "classes/user.php";

    if((isset($_POST["submit"]))    and $_POST["verificaation"]=="submit1"){
        $nom        =   $_POST["nom"];
        $prenom     =   $_POST["prenom"];
        $email      =   $_POST["email"];
        $username   =   $_POST["username"];
        $pass       =   $_POST["password"];
        $passver    =   $_POST["passver"];
        $conect=new dbconnect();

        $user= new user($username,$conect-&gt;connect);
        $msg=$user-&gt;register($nom,$prenom,$email,$user,$pass);
        print_r ($conect);


    }




?&gt;
&lt;form method="post" action="register.php"&gt;
&lt;label&gt;Nom&lt;/label&gt;
&lt;input type="text" name="nom"/&gt;&lt;br /&gt;
&lt;label&gt;Prenom&lt;/label&gt;
&lt;input type="text" name="prenom"/&gt;&lt;br /&gt;
&lt;label&gt;Email&lt;/label&gt;
&lt;input type="email" name="email"/&gt;&lt;br /&gt;
&lt;label&gt;Nom d'utilisateur&lt;/label&gt;
&lt;input type="text" name="username" /&gt;&lt;br /&gt;
&lt;label&gt;Mot de passe&lt;/label&gt;
&lt;input type="password" name="password" /&gt;&lt;br /&gt;
&lt;label&gt;Recrivez le mot de passe&lt;/label&gt;
&lt;input type="password" name="passver"/&gt;&lt;br /&gt;
&lt;input type="submit" name="submit" value="submit" /&gt;&lt;br /&gt;
&lt;input type="hidden" name="verificaation" value="submit1" /&gt;


&lt;/form&gt;
</code></pre>
