Parse error declaring a variable in a function?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Tony121076
New php-forum User
New php-forum User
Posts: 28
Joined: Fri Jan 03, 2003 4:00 pm

Parse error declaring a variable in a function?

Postby Tony121076 » Sat Feb 01, 2003 7:34 am

I keep getting a parse error when trying to declare a simple string variable from with a function (using PHP). I can do things like...

$db = mysql_connect("localhost", "user", "pass");

but if I try...

$this = "that";

I get a parse error on the line.
What's wrong? Please let me know if I'm not providing enough information. Thank you for you time and attention.

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Sat Feb 01, 2003 9:41 am

a little more info would help.
the only problem I see at the moment is the variable name.
'$this' is an object reference and as such shouldn't be attributed a value.
$this->varname = "value"; would be fine once the object has been instantiated.

what exactly are you trying to achieve?

on a different slant: if your function is not within a class, try globalizing the variable first

function blat()
{
global $fooey;
$fooey = "word";
}

Tony121076
New php-forum User
New php-forum User
Posts: 28
Joined: Fri Jan 03, 2003 4:00 pm

My error - Missing quote 3 lines up

Postby Tony121076 » Sat Feb 01, 2003 9:48 am

Thank you for taking the time to respond. I'm sorry to report that the error was being cause due to a missing quotation mark 3 lines up. I must had looked at it at least 10 times, and never noticed it.

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Sat Feb 01, 2003 10:30 am

that's ok - just glad you got the glitch sorted.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest