Page 1 of 1

PHP Class not working

Posted: Mon Oct 24, 2005 2:55 pm
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]

Posted: Mon Oct 24, 2005 3:45 pm
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();

?>

Posted: Mon Oct 24, 2005 10:01 pm
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.

Posted: Mon Oct 24, 2005 10:10 pm
by d3ad1ysp0rk
Maybe I'm mistaken, but I don't believe you need a constructer, especially if you're not using it for anything.

Posted: Tue Oct 25, 2005 10:41 am
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.

Posted: Tue Oct 25, 2005 11:31 am
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).