I use a lot of objects in my code, including database objects with data returned as objects. Simple matter, keeps code a little bit cleaner than arrays. But I noticed that foreach loops that are iterating through objects (at least in the places I have looked so far) are not running. The server seems to just skip over the code.
If I do a print_r() on the variable I see the object in all its glory looking great. I did that right before the loop. So then I moved into the loop itself and tried to echo something at the very beginning, nothing. Not good.
Now I want to remind you that this is on the production server, if I check out the same code and output on the dev server it goes into the loop and works fine. So my next thought was that maybe there is a corrupt file on the server. So I tried copying over just that file. That didn't work. Scratching my head I decided to check out trusty phpinfo(). It told me that the dev server is running 5.2.6 and that the production server is running 5.1.6.
So my thoughts at this point are maybe there is a PHP version problem. Unfortunately getting IT to upgrade to 5.2.6 on the production server will be difficult since there are a lot of websites running from that server.
Are there any known issues with foreach and objects in 5.1? Are there any changes you can suggest aside from switching all my code to use arrays instead of objects to hold data?
The only other thing I can add is I did all this in CodeIgniter v1.7.1.
Here is a sample of the code...
Code: Select all
foreach($questions_answers AS $qa):
?>
<div class="question_block">
<div class="question">
<?=form_hidden('questions[]', $qa->question_id)?>
<div class="question_num"><?=form_label('Question #'. $i, $qa->question_id)?></div>
<div class="question_text"><?=$qa->question?></div>
</div>
<div class="question_answers">
<?php
$validate_tag = FALSE;
foreach ($qa->answers AS $a):
if ($a->answer_id == set_value('qag_'. $qa->question_id))
$checked = TRUE;
else
$checked = FALSE;
$input_params = array(
'name' => 'qag_'. $qa->question_id,
'value' => $a->answer_id,
'checked' => $checked
);
if ($validate_tag != TRUE)
{
$input_params['class'] = 'required';
$validate_tag = TRUE;
}
?>
<div class="answer">
<?=form_radio($input_params)?>
<?=form_label($a->answer)?>
</div>
<?php endforeach; ?>
</div>
</div>
<?php
$i++;
endforeach;
Code: Select all
<div class="question_block">
<div class="question">
<input type="hidden" name="questions[]" value="50" /> <div class="question_num"><label for="50">Question #2</label></div>
<div class="question_text">I'd prefer a job that requires less than 2 years training.</div>
</div>
<div class="question_answers">
<div class="answer">
<input type="radio" name="qag_50" value="28" class="required" /> <label>Strongly Agree</label> </div>
<div class="answer">
<input type="radio" name="qag_50" value="27" /> <label>Agree</label> </div>
<div class="answer">
<input type="radio" name="qag_50" value="26" /> <label>Neutral</label> </div>
<div class="answer">
<input type="radio" name="qag_50" value="25" /> <label>Disagree</label> </div>
<div class="answer">
<input type="radio" name="qag_50" value="24" /> <label>Strongly Disagree</label> </div>
</div>
</div>
Thanks in advance for time and help.
-Patrick