New to Classes and having problems
Posted: Tue Feb 24, 2009 2:21 pm
Hi all! Well I have done several net searches and forum searches for my answer. I have found some, but nothing that helps me understand what it is that I'm doing wrong.
I am fairly new to PHP but do understand most of the basics. I also have a very good grasp of x/html as well. I just purchased the book PHP in Action - Ojects, Design, Agility. I was working with some of the first examples and everything was going fine until Inheritance and Extend came along.
Here is my code that I am trying:
I keep getting this error now matter what i change or do to the script.
I understand that the child class will inherit everything from the parent and then can be further changed on its own to add extended functionality. 1- I am missing an argument. 2- Not sure extactly how to call classes that have been extended.
Any help would be nice. Thanks in advance!
I am fairly new to PHP but do understand most of the basics. I also have a very good grasp of x/html as well. I just purchased the book PHP in Action - Ojects, Design, Agility. I was working with some of the first examples and everything was going fine until Inheritance and Extend came along.
Here is my code that I am trying:
Code: Select all
[color=#FF0000]<?php[/color]
[color=#408000]class[/color] HtmlDocument {
[color=#0000FF]function[/color] getHtml() {
[color=#408000]return[/color] [color=#FF0000]"[/color]<html><body>[color=#FF0000]"[/color] . [color=#00FFFF]$this[/color]->getContent() . [color=#FF0000]"[/color]</body></html>[color=#FF0000]"[/color];
}
[color=#0000FF]function[/color] getContent() { [color=#408000]return[/color][color=#FF0000] ''[/color]; }
}
[color=#408000]class[/color] HelloWorld [color=#408000]extends[/color] HtmlDocument {
[color=#408000]public [/color]$world;
[color=#0000FF]function[/color] __construct($world) {
[color=#00FFFF]$this[/color]->name = $world;
}
[color=#0000FF]function[/color] getContent() {
[color=#008000]return[/color] [color=#FF0000]"[/color]Hello, [color=#FF0000]"[/color].[color=#00FFFF]$this[/color]->name .[color=#FF0000]"[/color]![color=#FF0000]"[/color];
}
}
$greet = [color=#408000]new[/color] HelloWorld;
[color=#0000FF]echo[/color] $greet->getHtml();
[color=#FF0000]?>[/color]I keep getting this error now matter what i change or do to the script.
Code: Select all
Warning: Missing argument 1 for HelloWorld::__construct(), called in /Users/charles/Sites/Testing PHP/index.php on line 26 and defined in /Users/charles/Sites/Testing PHP/index.php on line 15
Hello, !
Any help would be nice. Thanks in advance!