/    Sign up×
Community /Pin to ProfileBookmark

New to classes – help please? (Don’t hit me!)

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>”;[/code]

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”;[/code]

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[/COLOR]

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…………………..*

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYJan 03.2006 — yes, forgetting a semi-colon can happen..it can be tricky to spot if you have a few hundred/thousand of lines of code ?

good night!
Copy linkTweet thisAlerts:
@NogDogJan 03.2006 — Glad we could help.

?
×

Success!

Help @mikeWarners spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...