Forum Moderators: coopster
Here's what I have so far:
<?phpclass Banner
{
var $startX;
var $startY;
var $textColor;
var $textSize;
var $text;
var $dataFile;
//var $delim = "¦";
function Banner($x1, $y1, $tc, $ts, $t, $df)
{
$this -> startX = $x1;
$this -> startY = $y1;
$this -> textColor = $tc;
$this -> textSize = $ts;
$this -> text = $t;
$this -> dataFile = $df;
}
function createFile()
{
$fh = fopen($dataFile, "a");
if(!$fh)
{
die("unable to open $dataFile);
}
fwrite($fh, $startX.$startY.$textColor.$textSize.$text);
fclose($fh);
}
}
$object = new Banner(1, 2, 3, 4, 5, 6);
object.createFile();
?>
Any tips?
I changed the code to just display what values are in the object and not try to write anything to a file, and the values are showing up fine. This is what I changed to:
class Banner
{
var $startX;
var $startY;
var $textColor;
var $textSize;
var $text;
var $dataFile;
//var $delim = "¦"; function Banner($x1, $y1, $tc, $ts, $t, $df)
{
$this -> startX = $x1;
$this -> startY = $y1;
$this -> textColor = $tc;
$this -> textSize = $ts;
$this -> text = $t;
$this -> dataFile = $df;
}
}
$object = new Banner(1, 2, 3, 4, 5, 6);
echo "<pre>";
print_r($object);
echo "</pre>";
?>
And this is what it outputs:
banner Object
(
[startX] => 1
[startY] => 2
[textColor] => 3
[textSize] => 4
[text] => 5
[dataFile] => 6
)
I just can't figure out how to get the methods in the object to do stuff with the properties in the class (which are storing properly). Any help is appreciated!
function createFile()
{
$fh = fopen($this->dataFile, "a");
if(!$fh) {
die("unable to open $this->dataFile);
}
fwrite($fh, $startX.$startY.$textColor.$textSize.$text);
fclose($fh);
}
$object = new Banner(1, 2, 3, 4, 5, 6);
//object.createFile(); <-- this is not correct syntax
$object->createFile();