Inheriting From Abstract Classes

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 999 Views - Last Post: 04 October 2012 - 12:26 PM Rate Topic: -----

#16 Tenderfoot  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 160
  • Joined: 21-March 12

Re: Inheriting From Abstract Classes

Posted 04 October 2012 - 11:25 AM

View PostCTphpnwb, on 04 October 2012 - 11:10 AM, said:

No, your child class inherits all of the abstract class variables.

I think your teacher wants to demonstrate that the child class will overload the abstract class definition of the function.


Maybe so, but I still think the instructions could have been clearer. I should be having trouble implementing it, not interpreting it. But thank you though, that might be an explanation for that part. What do you think I should do about the set/get functions though? I have them in the abstract class, which means, the child class should inherit them. I can use $this->setFornafn in the child class for an example, but when I call $this->fornafn the variable contains nothing. So that would indicate I was wrong about that part.

But thank you guys for your patience - I tend to over-analyze everything and that can be problematic.
Was This Post Helpful? 0
  • +
  • -

#17 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2988
  • Posts: 10,323
  • Joined: 08-August 08

Re: Inheriting From Abstract Classes

Posted 04 October 2012 - 11:30 AM

It's better to show us what you're doing than describe it. That way we can tell you exactly why a variable has the wrong or no value.

-- Although describing the problem is always a good idea too!
Was This Post Helpful? 1
  • +
  • -

#18 Tenderfoot  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 160
  • Joined: 21-March 12

Re: Inheriting From Abstract Classes

Posted 04 October 2012 - 11:39 AM

View PostCTphpnwb, on 04 October 2012 - 11:30 AM, said:

It's better to show us what you're doing than describe it. That way we can tell you exactly why a variable has the wrong or no value.

-- Although describing the problem is always a good idea too!


Hold on, it works! I feel like the light bulb in my head finally turned on when I saw that. ^^

It must have been misspelled or something like that before, this is the code I used:

	function __construct($fornafn, $eftirnafn, $laun)
	{
		//$this->fornafn = $fornafn; 
		//$this->eftirnafn = $eftirnafn;
		$this->setFornafn($fornafn);
		$this->setEftirnafn($eftirnafn);
		$this->setLaun($laun);
	}

	function __toString()
	{
		return "Nafn: $this->fornafn $this->eftirnafn - laun eru $this->laun"; 
	}



The above code is in the child class. All of the set functions I defined in the abstract class. This makes sense, finally. It didn't work earlier for some reason, I don't know what it was. But I really appreciate all of your effort to help me understand. Now the remaining issue is that I don't know what to do with the income function, but it isn't described at all so I'll take that up with my teacher. Thanks again!
Was This Post Helpful? 0
  • +
  • -

#19 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,232
  • Joined: 08-June 10

Re: Inheriting From Abstract Classes

Posted 04 October 2012 - 12:26 PM

it didnít work because they were private properties. when you called the properties in the child class, PHP on-the-fly created another set of properties (public, in the current class) as the properties of the abstract class were invisible. and since the properties were separated, setting $this->fornafn cannot affect the output of $this->getFornafn().
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2