views:

106

answers:

2

I have made a class in php which is goind to be inherited by another class in the other folder. when i put echo $this->protectedvariableofclass; //in subclass function it gives no value remember my base class is stored \class\user.php sublass is stored as \model\model_user.php Please help me out Thanks in advance

Base Class in \class\user.php

<?php

class user

{
     protected $user_id;
     //setter method
public function set_user_id($user_id)
 {

            $this->user_id=$user_id;
 }
     //getter method
     public function get_user_id()
     {
                return $this->user_id;
     }

}
?>      

Subclass in \model\model_user.php

<?php

require_once 'class/user.php';

class model_user extends user
{
public function checkUser()

    {

   echo $this->user_id;
   $sql = "SELECT * FROM user WHERE user_id='$this->user_id'";
        $result = mysql_query($sql);
        if(!result)
        {
         die('error'.mysql_error());
        }
        $duplicates = mysql_num_rows($result);
        if($duplicates > 0)
            return 1;
        else
            return 0;

    }

}
A: 

Everything I see is that you're trying to output user_id which is not assigned anywhere in the posted code.

Andy
actully it is assigned in the index.php in root folder by using $myuser->set_user_id($user);
Abhishek
+1  A: 

Maybe you have done this already, but in case you're not, try this:

$model_user = new model_user();
$model_user->set_user_id(5);

$model_user->checkUser(); // Should output 5
Andree