Question

I have created a session variable to store some basic stats:

 $_SESSION['stats'] = array('likecount' => 0, 'failedlikes' => 0);

Further down I have a line which increments it:

$_SESSION['stats']->likecount++;

However, this throws the error Attempt to increment/decrement property of non-object. What am I doing wrong?

Was it helpful?

Solution

You're dealing with an array, not with an object, so you should use

$_SESSION['stats']['likecount']++; 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top