Unexpected output from very simple class
Posted: Thu Jul 06, 2006 3:51 am
Hi guys,
I'm just trying to get to grips with OO PHP, and am having trouble with the following very simpl class:
Using the following code to instantiate and outpt it
produces the following HTML output:
You will see from this that $table2->data is outputting in the wrong place. Why would that be? Also, I appreciate that there is no need for a function to echo out $data in this case, but am trying underpin the principal of using one.
Thanks in advance...
I'm just trying to get to grips with OO PHP, and am having trouble with the following very simpl class:
Code: Select all
class create_Table {
var $width;
var $height;
var $border;
var $rows;
var $content;
var $data;
function create_Frame ( ) { // create the framework for the table
echo "<table border = ". $this->border ." width = ". $this->width ."% height = ". $this->height .">\n";
$num = 1;
$rows = $this->rows;
while ( $num <= $rows ) {
echo "<tr><td>". $this->content ."</td><td>Function call: ". $this->add_Data ( ) ."</td></tr>\n";
$num++;
}
echo "</table>\n";
} // end of function create_Frame ( )
function add_Data( ) { // Add some data to the cells calling this function
echo $this->data;
}
} // end of classCode: Select all
$table2 = new create_Table ( );
$table2->data = "Hello world";
$table2->width = "100";
$table2->height = "200";
$table2->border = "2";
$table2->rows = "4";
$table2->content = "Second table";
$table2->create_Frame ( );Code: Select all
<table border = 2 width = 100% height = 200>
Hello world<tr><td>Second table</td><td>Function call: </td></tr>
Hello world<tr><td>Second table</td><td>Function call: </td></tr>
Hello world<tr><td>Second table</td><td>Function call: </td></tr>
Hello world<tr><td>Second table</td><td>Function call: </td></tr>
</table>Thanks in advance...