Using $this when not in object context--i am using the latest version of php and mysql

Posted by user309381 on Stack Overflow See other posts from Stack Overflow or by user309381
Published on 2010-04-19T06:06:23Z Indexed on 2010/04/19 6:13 UTC
Read the original article Hit count: 248

Filed under:
|

This is user.php:

    include("databse.php");//retrieving successfully first name and lastname from databse file into user.php
    class user
    {
      public $first_name;
      public $last_name;
      public static function full_name()
      {
          if(isset($this->first_name) && isset($this->last_name))
          {
            return $this->first_name . " " . $this->last_name;

          }
          else
           {
                return "";
           }
       }
    }
?>

Other php file, index.php:

<?php
   include(databse.php);
   include(user.php);
    $record = user::find_by_id(1);
    $object = new user();
    $object->id = $record['id'];
    $object->username = $record['username'];
    $object->password = $record['password'];
    $object->first_name = $record['first_name'];
    $object->last_name = $record['last_name'];
    // echo   $object->full_name();
    echo $object->id;// successfully print the id
    echo $object->username;//success fully print the username
    echo->$object->full_name();//**ERROR:Using $this when not in object context**

?>

© Stack Overflow or respective owner

Related posts about php5

Related posts about php