Sign in to follow this  
Followers 0
yucatan

global $var

5 posts in this topic

hi i have a $var and that is used in a func and it get declared in a func so i wanne do add something

global $item += 3

why that dont work

i want in a func to do this

global $item += 3

when i do that i get syntax error

when i do

$item += 3

the $var changes in that func but not in another func..

how i can fix this ?

Share this post


Link to post
Share on other sites



If you need your $item variable to be a global one then declare it somewhere inside your main script.

"Global $item" will create the variable in the global scope (know all over the script).

After you create the variable you can increment it, that's why you get an error for "global $item += 3"


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

If you need your $item variable to be a global one then declare it somewhere inside your main script.

"Global $item" will create the variable in the global scope (know all over the script).

After you create the variable you can increment it, that's why you get an error for "global $item += 3"

teh whole func is in a func i cannot run that part in the main script it just cant there got to be a way:S...

Share this post


Link to post
Share on other sites

Then break that line:

Global $item
$item +=3

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

That will reinitialize $item to 0.

At the top of your script (OUTSIDE the func) just put Global $item.

Tadaa, no problems.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0