php constructor is not working correctly with error query() on null
<p>As you can see from item.php, I have 2 functions to display some items</p>

<p><strong>display_item_1() and display_item_2()</strong></p>

<p>When I run the program by calling</p>

<pre><code>$item = new item();
$item-&gt;display_item_1(1);
$item-&gt;display_item_2(1);
</code></pre>

<p><strong>It only displays function->display_item_1()</strong>  </p>

<p><strong>but for display_item_2() receives Fatal error: Call to a member function query() on null</strong> </p>

<p>In other words, both function display_item_1() and display_item_2() are same coding but just display the 1st one. 
So that means the <strong>constructor in item.php is not correct?</strong> </p>

<p>OR which part did i do wrong?</p>

<p><strong>db.php</strong></p>

<pre><code>class db{

protected $db_host;
protected $db_name;
protected $db_user_name;
protected $db_pass;

public function __construct() {
$this-&gt;db_host="localhost";
$this-&gt;db_name="bs";
$this-&gt;db_user_name="root";
$this-&gt;db_pass="";
}

public function conn(){

try {   
    $conn = new PDO("mysql:host=$this-&gt;db_host;dbname=$this-&gt;db_name", $this-&gt;db_user_name="root", $this-&gt;db_pass);
    $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $conn;
}
catch(PDOException $e)
    {
    echo $sql . "&lt;br&gt;" . $e-&gt;getMessage();
    }
}
}
</code></pre>

<p><strong>item.php</strong></p>

<pre><code>require "db.php";

class item {

public $user_uid;
protected $item_name;
public $conn;

public function __construct(){
    $db = new db();
    $this-&gt;conn= $db-&gt;conn();

}

public function display_item_1($uid){

    $this-&gt;user_uid=$uid;

    try{
        $sql="SELECT * FROM item where uid='$this-&gt;user_uid'";
        $statement=$this-&gt;conn-&gt;query($sql);
    }
    catch(PDOException $e){
        ... 
    }

}

public function display_item_2($uid){

    $this-&gt;user_uid=$uid;

    try{
        $sql="SELECT * FROM item where uid='$this-&gt;user_uid'";
        $statement=$this-&gt;conn-&gt;query($sql);
        }

    }
    catch(PDOException $e){
        ...
    }

}
}
</code></pre>