Jump to content
xisto Community

Search the Community

Showing results for tags 'OOP'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Help & Support
    • Alerts, News & Announcements
    • Web Hosting Support
    • Introductions
  • Computers & Tech
    • Science and Technology
    • Software
    • The Internet
    • Search Engines
    • Graphics, Design & Animation
    • Computer Gaming
    • Websites and Web Designing
    • Mobile Phones
    • Operating Systems
    • Programming
    • Online Advertising
    • Hardware Workshop
    • Computer Networks
    • Security issues & Exploits
  • Others
    • General Discussion
    • Business Forum
    • Photography
    • Health & Fitness
    • Dating And Relationships
    • The Vent
    • Art & Creativity
    • Home & Garden

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Location


Interests

Found 1 result

  1. I am trying to get into the Object Oriented Programming (OOP) in the PHP. For this I have installed a local apache server to test my work and experiment with my scripting techniques. Until today everything was going fine and my learning speed was good. But I have come to face a problem to which I have no answer. I am trying to create a user class for a test project. The code of the user class is as follows: <?phprequire_once("database.php");class User {public $id;public $username;public $password;public $first_name;public $last_name;public static function find_all() { return self::find_by_sql("select * from users");}public static function find_by_id($id=0) { global $database; $result_array=self::find_by_sql("Select * from users where id={$id} limit 1"); if (!empty($result_array)) { return array_shift($result_array); } else { return FALSE; }}public function find_by_sql($sql="") { global $database; $result_set=$database->query($sql); $object_array=array(); while ($row=$database->fetch_array($result_set)) { $object_array[]=self::instantiate($row); } return $object_array;}public function full_name() { if (isset($this->first_name)&& isset($this->last_name)) { return $this->first_name." ".$this->lastname; } else { return ""; }}private static function instantiate($record) { $object=new self; $object->id=$record['id']; $object->username=$record['username']; $object->passwrod=$record['password']; $object->first_name=$record['first_name']; $object->last_name=$record['last_name']; return $object;}}?> As you can see in the code, I have created a User class with few attributes and methods. The code is clean and there is no problem in it. On the index page, I have the following code: $user=User::find_by_id(1);echo $user->full_name(); Theoretically, the code should return the full name of a user but instead when I run the code, I get the following error: ( ! ) Fatal error: Call to a member function full_name() on a non-object in C:\wamp\www\imagepro\public\index.php on line 8Call Stack# Time Memory Function Location1 0.0014 669408 {main}( ) ..\index.php:0 And I don't understand why I am getting this error. It says that I am making a call to an object function from a non-object. But as per the code in the instantiate method of the user class, the object should get automatically instantiated. I have spend more than an hour just to figure out any mistake in the code but I am unable to find it. So the last guess that is left with me is that there are some settings that I need to change in the php.ini file on my localhost. Any help from the experts is appreciated. Thanks in advance
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.