WTF ... IS WTF!?
We are a collective of people who believe in freedom of speech, the rights of individuals, and free pancakes! We share our lives, struggles, frustrations, successes, joys, and prescribe to our own special brand of humor and insanity. If you are looking for a great place to hang out, make new friends, find new nemeses, and just be yourself, WTF.com is your new home.

PHP Class confusion!

Blaze Daily

<b>Banned - What an Asshat!</b>
146
0
0
#1
<?PHP

class htm {
// Declare varibles to store HTML
var $body;

// Add content to $body
function give_body ($content) {
$this->body = $content;
}
// End class.
}

//create class
$output = new htm;

$content = "<HTML><BODY>HELLO WORLD</BODY></HTML>";
//Add content to $body
$output->give_body ($content);

//output HTML
print $output->$body;

?>
This is the code I'm currently working on, I need a lil help.

Can any PHP coder see what the fuck is wrong with this code?

Basically, I create a class that holds the variable $body. I have a simple function to concationate (sp) the variable with HTML code. Finally, I want to output this code to the browser. However, this does not work with my computer, or my server. This is my first time working with classes, so please excuse my ignorance.

Y'see - I'm thinking of creating a class structure to build simple HTML pages, and so far this is how far I got and I'm already stuck - please help :)
 

Blaze Daily

<b>Banned - What an Asshat!</b>
146
0
0
#2
Figured it out...

It's the very last line of code that was (kinda obviously) the problem since that is the variable being outputted, and there was no output from the script.

Instead of;
//output HTML
print $output->$body;

I should have wrote;
print $output->body;

The body doesn't have a $, a silly mistake, I know, but frustrating nevertheless.

Thanks for the people who looked in, trying to help. But I figured it out in the end, and my HTML class construction ting is slowly starting to take shape. Always wanted to use class constructs for HTML :)