pintee Posted July 19, 2013 Share Posted July 19, 2013 This has been driving me crazy. When I put: for($i = 0; $i < sizeOf($clones); $i++) { $clones[$i]->attackGroup = $_POST['type'][$i]; } $clones[2]->attackGroup does not get assigned. But when I put: for($i = 0; $i < sizeOf($clones); $i++) { if($i == 2) { $clones[$i]->attackGroup = $_POST['type'][$i]; } } It does.....How is this possible???? Quote Link to comment Share on other sites More sharing options...
rythemton Posted July 19, 2013 Share Posted July 19, 2013 There is something missing. Both cases should work. Are there any error messages? Does this code work? foreach($clones as $key => &$value) { $value->attackGroup = $_POST['type'][$key]; } Without seeing more code, it's nearly imposible to figure out what's wrong. Quote Link to comment Share on other sites More sharing options...
pintee Posted July 19, 2013 Author Share Posted July 19, 2013 Thanks for the reply. No, it does not work. Putting $clones[2]->attackGroup = $_POST['type'][2]; works.....so why doesn't it work??? I just can't understand it..... Quote Link to comment Share on other sites More sharing options...
rythemton Posted July 19, 2013 Share Posted July 19, 2013 Let me verify a few things: $clones is an array, correct? $clones[2] is an object of some type, correct? Are $clones[0] and $clones[1] the same type of object? If $clones[0] and/or $clones[1] are not the same type of object as $clones[2] then trying to assign something to $clones[0 or 1]->attackGroup will throw an error and stop the script, and it will never get to $clones[2]. We difinetely need more information. Quote Link to comment Share on other sites More sharing options...
pintee Posted July 19, 2013 Author Share Posted July 19, 2013 $clones is an array. $clones[2] is an object. $clones[0] and $clones[1] are the same type of object. Interestingly....when I spell out the for loop explicitly: $clones[0]->attackGroup = $_POST['type'][0]; $clones[1]->attackGroup = $_POST['type'][1]; $clones[2]->attackGroup = $_POST['type'][2]; $clones[3]->attackGroup = $_POST['type'][3]; it does not assign.... but when i just have: $clones[2]->attackGroup = $_POST['type'][2]; it does....... Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 19, 2013 Share Posted July 19, 2013 Do you have on error reporting? error_reporting(-1); ini_set('display_errors', '1'); Quote Link to comment Share on other sites More sharing options...
Solution pintee Posted July 19, 2013 Author Solution Share Posted July 19, 2013 Huzzah! It turns out I was using a reference to the same object three times....so $i = 3 was overwriting $i = 2( $i = 3 was null.............thus giving the illusion that it was not being assigned...!!!) Quote Link to comment 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.