Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I have hit a brick wall in my project: PHP doesn't consider the $bon_v1 an array. What is wrong with all of this/ some of this?

$bon_r1 = array(
"in" => "#pp1",
"ot" => "bon-r1",
"fn" => "bon_r1()",
"js" => "$('bon-r1').val($('#pp1').val());",
"ep" => "not tested"
);
$bon_r2 = array(
"in" => "#pp2",
"ot" => "bon-r2",
"fn" => "bon_r2()",
"js" => "$('bon-r2').val($('#pp2').val());",
"ep" => "not tested"
);
$bon_ru = array(
"in" => "#username",
"ot" => "bon-ru",
"fn" => "bon_ru()",
"js" => "$('bon-ru').val($('#username').val());",
"ep" => "not tested"
);
$bon_rp = array(
"in" => "#password",
"ot" => "bon-rp",
"fn" => "bon_rp()",
"js" => "$('bon-rp').val($('#password').val());",
"ep" => "not tested"
);
$bon_rf = array(
"in" => "#firstname",
"ot" => "bon-rf",
"fn" => "bon_rf()",
"js" => "$('bon-rf').val($('#firstname').val());",
"ep" => "not tested"
);
$bon_rl = array(
"in" => "#lastname",
"ot" => "bon-rl",
"fn" => "bon_rl()",
"js" => "$('bon-rl').val($('#lastname').val());",
"ep" => "not tested"
);

$bon_1p = array(
"in" => "#password,#pp1",
"ot" => "bon-1p",
"fn" => "bon_1p()",
"js" => "ud = $('#password').val();udl= ud.length;p1 = $('#pp1').html();co = p1 + ud.charAt(udl - 3)+ ud.charAt(udl - 2)+ ud.charAt(udl - 1)+ ud.charAt(udl);$('#bon-1p').val(co);",
"ep" => "not tested"
);
$bon_1u = array(
"in" => "#username,#pp1",
"ot" => "bon-1u",
"fn" => "bon_1u()",
"js" => "ud = $('#username').val();udl= ud.length;p1 = $('#pp1').html();co = p1 + ud.charAt(udl - 3)+ ud.charAt(udl - 2)+ ud.charAt(udl - 1)+ ud.charAt(udl);$('#bon-1u').val(co);",
"ep" => "not tested"
);
$bon_pu = array(
"in" => "#username,#password",
"ot" => "bon-pu",
"fn" => "bon_pu()",
"js" => "ud = $('#username').val();udl= ud.length;p1 = $('#password').val();co = pw + ud.charAt(udl - 3)+ ud.charAt(udl - 2)+ ud.charAt(udl - 1)+ ud.charAt(udl);$('#bon-pu').val(co);",
"ep" => "not tested"
);
$bon_p1 = array(
"in" => "#password,#pp1",
"ot" => "bon-p1",
"fn" => "bon_p1()",
"js" => "p1 = $('#password').val();ud = $('#pp1').html();udl= ud.length;co = p1 + ud.charAt(udl - 3)+ ud.charAt(udl - 2)+ ud.charAt(udl - 1)+ ud.charAt(udl);$('#bon-p1').val(co);",
"ep" => "not tested"
);
$bon_u1 = array(
"in" => "#username,#pp1",
"ot" => "bon-u1",
"fn" => "bon_u1()",
"js" => "ud = $('#username').val();udl= ud.length;p1 = $('#pp1').html();co = ud.charAt(0)+ ud.charAt(1)+ ud.charAt(2)+ ud.charAt(3) + p1;$('#bon-1u').val(co);",
"ep" => "not tested"
);
$bon_up = array(
"in" => "#username,#password",
"ot" => "bon-up",
"fn" => "bon_up()",
"js" => "ud = $('#username').val();udl= ud.length;pw = $('#password').val();co = ud.charAt(0)+ ud.charAt(1)+ ud.charAt(2)+ ud.charAt(3) + pw;$('#bon-up').val(co);",
"ep" => "not tested"
);
$bon_wp = array(
"in" => "#password,#username",
"ot" => "bon-wp",
"fn" => "bon_wp()",
"js" => "ud = $('#password').val();udl= ud.length;p1 = $('#username').val();co = p1 + ud.charAt(udl - 3)+ ud.charAt(udl - 2)+ ud.charAt(udl - 1)+ ud.charAt(udl);$('#bon-wp').val(co);",
"ep" => "not tested"
);
$bon_w1 = array(
"in" => "#username,#pp1",
"ot" => "bon-w1",
"fn" => "bon_w1()",
"js" => "p1 = $('#username').val();ud = $('#pp1').html();udl= ud.length;co = p1 + ud.charAt(udl - 3)+ ud.charAt(udl - 2)+ ud.charAt(udl - 1)+ ud.charAt(udl);$('#bon-w1').val(co);",
"ep" => "not tested"
);

$bon_v1 = array($bon_r1,$bon_r2,$bon_ru,$bon_rp,$bon_rf,$bon_rl,$bon_1p,$bon_wp,$bon_w1);
share|improve this question
Scoping is my guess. – Corbin Jun 8 '12 at 23:00
works fine for me! is_array returns true and foreach works like a charm. PHP 5.3.8 (cli) – braunbaer Jun 8 '12 at 23:38

closed as off topic by Winston Ewert Jun 9 '12 at 3:53

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

up vote 1 down vote accepted

First of all, what in the world is going on? What are all these nasty, confusing, random strings?

Second, when you have repetitive code like this, look for a way to reduce the amount of times you have to type it. Doing so will ensure that all copies are the same so that if one is wrong, they all are wrong and you wont have to go searching for the culprit. Loops are wonderful for this. I'd be delighted to show you an example but I still can't get my brain around what you are trying to do.

I'd suggest using var_dump() on the arrays you are trying to push into $bon_v1 array to see what they return. I'm thinking your problem probably stems from the "js" elements having PHP identifiers "$" in them, but I can't be sure. If you aren't using PHP variables or escapable characters in a string use single quotes instead of double. Try converting your arrays to look like this and see if that helps.

$bon_r1 = array(
    "in" => '#pp1',
    "ot" => 'bon-r1',
    "fn" => 'bon_r1()',
    "js" => '$("bon-r1").val($("#pp1").val());',
    'ep' => 'not tested'
);
share|improve this answer
Thanks, I know it looks awful, but this is a transfer encryption mechanism, it's not supposed to make sense. – Andrejewski Jun 9 '12 at 3:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.