Suchy Posted September 3, 2011 Share Posted September 3, 2011 Im having problem extending a class. <?php // Parent class class Profile { protected $id, $result, $info; protected function get_id() { return $_GET['id']; } protected get_info() { $id = $this->get_id(); $result = mysql_query("SELECT * FROM profiles WHERE id = '$id' "); return mysql_fetch_array($result); } public get_fname() { $info = $this->get_info(); return $info['fname']; } public get_lname() { $info = $this->get_info(); return $info['lname']; } } // Child class class Profile_new extends Profile { protected get_info() { $id = $this->get_id(); $result = mysql_query("SELECT * FROM new_profiles WHERE id = '$id' "); return mysql_fetch_array($result); } } // Webpage $profile = new Profile_new; $first_name = $profile->get_fname(); $last_name = $profile->get_lname(); ?> For some reason I still getting first + last names of people from the profiles table, and not from the new_profiles table. How can I fix this ? Quote Link to comment https://forums.phpfreaks.com/topic/246377-extending-classes/ Share on other sites More sharing options...
mikesta707 Posted September 3, 2011 Share Posted September 3, 2011 Well, you marked this topic as solved, but the reason is you that when accessing a base classes methods, once inside those methods you only have access to other base class attributes/methods. So even though you overrided the base classes method, while inside the other method of the base class, it doesn't know of your override more of less. I can discuss this in more detail if you would like. Quote Link to comment https://forums.phpfreaks.com/topic/246377-extending-classes/#findComment-1265199 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.