Phalanxer Posted June 29, 2012 Share Posted June 29, 2012 I was using: if ($_POST['num'] == '3') { $_SESSION['number1']++; } ... and everything was fine. Now I am using: if ($_POST['num'] == '3') { $_SESSION['tablea']['number1']++; } ... and getting: Cannot increment/decrement overloaded objects nor string offsets Does anyone know what has caused this? Quote Link to comment https://forums.phpfreaks.com/topic/264985-cant-incrementdecrement-overloaded-objects-nor-string-offsets/ Share on other sites More sharing options...
boompa Posted June 29, 2012 Share Posted June 29, 2012 In order to use an increment/decrement, the variable being incremented or decremented must exist and have a value. What if you do if ($_POST['num'] == '3') { print_r($_SESSION['tablea']); $_SESSION['tablea']['number1']++; } Does that demonstrate that the key number1 exists as a member of $_SESSION['tablea']? Is $_SESSION['tablea'] an array? Quote Link to comment https://forums.phpfreaks.com/topic/264985-cant-incrementdecrement-overloaded-objects-nor-string-offsets/#findComment-1357916 Share on other sites More sharing options...
Phalanxer Posted June 29, 2012 Author Share Posted June 29, 2012 What I did to fix it was: $_SESSION['tablea']['number1'] = $_SESSION['tablea']['number1'] + 1; Quote Link to comment https://forums.phpfreaks.com/topic/264985-cant-incrementdecrement-overloaded-objects-nor-string-offsets/#findComment-1357923 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.