PHP Class not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rahma
Forum Newbie
Posts: 5
Joined: Mon Oct 24, 2005 2:44 pm

PHP Class not working

Post by rahma »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi All

I am new to php, php page is not displaying whenever I use Class.  

Following is my code, which is not displaying anything, simply displaying the blank page.

I am using PHP Version 5.0.4.

Can you please help to solve this problem.

Thanks in Advance
Regards
Rahma

Code: Select all

<?php

class TextBoxSimple {
var $body_text = "my text"
function display() {
print("<TABLE BORDER=1><TR><TD>$this->body_text");
print("</TD></TR></TABLE>");
}
}

$box = new TextBoxSimple();
print "......hello..........";
$box->body_text = "custom text";
$box->display();
?>

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

You don’t have a constructor function and you are missing a ‘;’ on the line (var $body_text = "my text";
)

Code: Select all

<?php



class TextBoxSimple {
var $body_text = "my text";	
function TextBoxSimple(){}

function display() {
print("<TABLE BORDER=1><TR><TD>$this->body_text");
print("</TD></TR></TABLE>");
}
}

$box = new TextBoxSimple();
print "......hello..........";
$box->body_text = "custom text";
$box->display();

?>
rahma
Forum Newbie
Posts: 5
Joined: Mon Oct 24, 2005 2:44 pm

Post by rahma »

Thanks a lot man, its working fine.

Is there any way to display this type of syntax errors or some sort of compilier thing.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Maybe I'm mistaken, but I don't believe you need a constructer, especially if you're not using it for anything.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

No you don't "Have" to have one. IMHO its a good idea for people learning OOP to always have one. You are correct though, that wasn't the cause of the error as I stated above.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Check your PHP configuration file and ensure any setting for displaying errors is enabled. Can also set error_reporting() in your scripts. Might be logging the errors by default rather than display them (a safer default for public servers).
Post Reply