tags:

views:

43

answers:

1
function do_something()
{
static first_time = true;
if (first_time) {
// Execute this code only the first time the function is
➥called
...
}
// Execute the function's main logic every time the function is
➥called
...
}

it's bring up this error

Parse error: parse error, expecting `T_VARIABLE' in C:\wamp\www\functions.php on line 3
+4  A: 

This is not valid PHP. You need to define variables preceded with a $ character.

Frankly, when I saw your code, initially I thought it may be JavaScript, but then I saw the static keyword... What language could he be using now? Java? No function keyword there.... That was when I saw the tag php....

function do_something() {
    static $first_time = true;
    if ($first_time) {
       //...
    }
}

That will work.

(A bit of advice: look over your code at least a couple of times before posting here, this was quite an elementary issue)

Jacob Relkin
@jacob I noticed it before, but the incredible thing is that it was a cut and past from the PHP 5 Power Programming book. i can't believe this books has come out without proofreading it....Thanks
jona
oh the number of times I've done that in c++, "its got a blue word in front of it's deceleration, I must have given it a type"
matt
Unbelievable. They should get rid of all of their technical reviewers and hire real ones. !!!
Jacob Relkin
I don't know if they should but it is a big typo for a big book.
jona