Hi guys,
I’ve just started to dip my toes into OOP and classes in PHP, and I’ve been following my textbook so far (SAMS PHP in 24 hours) – but I’ve hit a snag.
I’m using what looks to be more or less a replica of the script from the book:
[code=php]// I’m trying something new here. CLASSES!!!!!!!!!
class Uploader{
var $name = “foo”;
var $destinationDir = “bar”;
var $newName = “newFoo”;
function setName($n){
$this->name = $n;
}
}
$fileUpload = new Uploader();
print “$fileUpload is an “.getType($fileUpload).”<br />”;
print “The name property in $fileUpload is set to “.$fileUpload->name.”<br>”;
print “I’m now going to change it.<br>”
$fileUpload->setName(“newFooTwo”);
print “Right, it’s changed.<br>”
print “The name property in $fileUpload is <i>now</i> set to “.$fileUpload->name.”<br>”;
But my script is erroring on line 18 of the above code, where I attempt to change the value of $fileUpload’s name variable (I also tried it without the function, using
[code=php]$fileUpload->name=”newFooToo”;
but that didn’t work either.
This is probably really basic and blindingly obvious, but I’m really tired right now and I can’t for the life of me figure out what’s going wrong. Any ideas guys?
[COLOR=Red]EDIT – fixed it
I said I was tired…. I didn’t put the semicolons at the end of the ‘Print’ lines.
D’OH!
I feel so frickin’ stupid right now.
You see, this is what I get for developing in ASP all day, and coming home at night and trying to code in PHP.
I’ll leave you all alone now, and go and get some sleep.
‘Night everybody!
*ZZZZZZZZZZZZZZZZZZZZZZZ…………………..