venturemc Posted September 24, 2009 Share Posted September 24, 2009 I think I just need another set of eyes here. I have a simple function that performs up until the return clause. Have no idea where it's breaking down, but when I go back to the function call, the variable is empty. The same concept is working fine before and after this call.... calling script ........ extract(get_hdr_ary());//<----- works fine $cri_page->get_wphdr($dt,$html,$meta,$link,$title); extract(get_el_ary_cri()); //<-----------problem-------------- $cri_page->get_wpel_ary($el_ary_cri); extract(get_td_ary_cri()); //<----------works fine $cri_page->get_wp_table($style, $tda,$tcs, $tcp); function script function get_lst_ary_ao(){ $lst_ary_ao = array(array('li'=> 'AND', 'selected'=>'t'), array('li'=> 'OR', 'selected'=> 'f') ); return $lst_ary_ao; } function get_el_ary_cri(){ $a_fldlst = get_lst_ary_fn(); $a_oplst = get_lst_ary_op(); $el_ary_cri = array(array('eltype'=>'ls', 'name'=> 'fldlst'.$_SESSION['rowcount'], lbl'=> 'select_field', 'dflt'=>"",'lsttype'=> 'n', 'lstpop'=>$a_fldlst, 'lstpop_type'=>'a', 'multi'=>'f', 'size'=>1,'html' =>''), array('eltype'=>'ls', 'name'=> 'oplst'.$_SESSION['rowcount'], 'lbl'=> 'select_operater', 'dflt'=>"=",'lsttype'=> 'n', 'lstpop'=>$a_oplst, 'lstpop_type'=>'a', 'multi'=>'f', 'size'=>1, 'align'=>'center','html' =>''), array('eltype'=>'tx', 'name'=> 'criteria'.$_SESSION['rowcount'], 'lbl' =>'enter_criteria_value', 'align'=>'left','size'=>40, 'html'=> ''), array('eltype'=>'ab', 'name'=> 'add_row'.$_SESSION['rowcount'], 'lbl'=> 'add_row', 'html' =>''), array('eltype'=>'sb', 'name'=> 'submit_cri', 'lbl'=> 'submit', 'html' =>'') ); return $el_ary_cri;// <---------everything is fine at this point } function get_td_ary_cri(){ $tda_ary_cri = array('style' => 4, 'tda' => array(array('row_index'=> 1, 'col_count'=>4,'col_align'=> 'left', 'colspan'=> 1) ), 'tcs'=>1, 'tcp'=>2, ); return $tda_ary_cri; } at the return statement, I have the expected variable contents, but nothing when it gets back to the calling page. other times I've encounterd this type of problem I've found typos, but I can't see anything wrong here Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 24, 2009 Share Posted September 24, 2009 What does this output: function get_el_ary_cri(){ $a_fldlst = get_lst_ary_fn(); $a_oplst = get_lst_ary_op(); $el_ary_cri = array(array('eltype'=>'ls', 'name'=> 'fldlst'.$_SESSION['rowcount'], lbl'=> 'select_field', 'dflt'=>"",'lsttype'=> 'n', 'lstpop'=>$a_fldlst, 'lstpop_type'=>'a', 'multi'=>'f', 'size'=>1,'html' =>''), array('eltype'=>'ls', 'name'=> 'oplst'.$_SESSION['rowcount'], 'lbl'=> 'select_operater', 'dflt'=>"=",'lsttype'=> 'n', 'lstpop'=>$a_oplst, 'lstpop_type'=>'a', 'multi'=>'f', 'size'=>1, 'align'=>'center','html' =>''), array('eltype'=>'tx', 'name'=> 'criteria'.$_SESSION['rowcount'], 'lbl' =>'enter_criteria_value', 'align'=>'left','size'=>40, 'html'=> ''), array('eltype'=>'ab', 'name'=> 'add_row'.$_SESSION['rowcount'], 'lbl'=> 'add_row', 'html' =>''), array('eltype'=>'sb', 'name'=> 'submit_cri', 'lbl'=> 'submit', 'html' =>'') ); echo '<pre>' . print_r( $el_ary_cri, true ) . '</pre>'; return $el_ary_cri;// <---------everything is fine at this point } I'm guessing your array doesn't have any associative indexes. Quote Link to comment Share on other sites More sharing options...
venturemc Posted September 24, 2009 Author Share Posted September 24, 2009 Hmmmm...I did mess with the indexes in a recent rewrite, so that could be the problem. I'll play with that this afternoon to see if that's it. Thanks for the eye..... Quote Link to comment Share on other sites More sharing options...
venturemc Posted September 24, 2009 Author Share Posted September 24, 2009 As much as I wanted the solution to be that easy, it didn't fix the problem. The variable (array) is created, but not returned to the calling script. Quote Link to comment Share on other sites More sharing options...
venturemc Posted September 24, 2009 Author Share Posted September 24, 2009 Interstingly, it works fine if I pass the array through a $_SESSION variable - it just doesn't return via the function return clause. Why would that be? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 25, 2009 Share Posted September 25, 2009 You never told me what it outputs. Quote Link to comment Share on other sites More sharing options...
venturemc Posted September 25, 2009 Author Share Posted September 25, 2009 Don't understand the question. THe function creates an array. Through a $_SESSION var it works; when using the function return, I get NULL. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 25, 2009 Share Posted September 25, 2009 I modified your function to print the value of the array before it returns. When you run it you should see extra output. Quote Link to comment Share on other sites More sharing options...
venturemc Posted September 25, 2009 Author Share Posted September 25, 2009 I didn't notice your post with the addition before. But my issue isn't at that point. When I reach the return statement, the array is as expected, but it won't show up at the calling script as it should. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 25, 2009 Share Posted September 25, 2009 I need to know what the array is just before it is returned; I'm not going to take your word that it is as expected because you might be mistaken. You can't be helped if you're not going to provide any information that will be useful in helping you. Quote Link to comment Share on other sites More sharing options...
venturemc Posted September 25, 2009 Author Share Posted September 25, 2009 Not trying to be evasive, didn't understand what you wanted: THis is the reults of a var_dump right before the "return" statement: (sorry hard to read) array(5) { [0]=> array(11) { ["row_index"]=> int(1) ["eltype"]=> string(2) "ls" ["name"]=> string(7) "fldlst1" ["lbl"]=> string(12) "select_field" ["dflt"]=> string(0) "" ["lsttype"]=> string(1) "n" ["lstpop"]=> array(3) { [0]=> array(3) { ["row_index"]=> int(1) ["li"]=> string(10) "first_name" ["selected"]=> string(1) "f" } [1]=> array(3) { ["row_index"]=> int(2) ["li"]=> string(9) "last_name" ["selected"]=> string(1) "f" } [2]=> array(3) { ["row_index"]=> int(3) ["li"]=> string(5) "email" ["selected"]=> string(1) "f" } } ["lstpop_type"]=> string(1) "a" ["multi"]=> string(1) "f" ["size"]=> int(1) ["html"]=> string(0) "" } [1]=> array(12) { ["row_index"]=> int(2) ["eltype"]=> string(2) "ls" ["name"]=> string(6) "oplst1" ["lbl"]=> string(15) "select_operater" ["dflt"]=> string(1) "=" ["lsttype"]=> string(1) "n" ["lstpop"]=> array(4) { [0]=> array(3) { ["row_index"]=> int(1) ["li"]=> string(1) "=" ["selected"]=> string(1) "t" } [1]=> array(3) { ["row_index"]=> int(2) ["li"]=> string(2) "!=" ["selected"]=> string(1) "f" } [2]=> array(3) { ["row_index"]=> int(3) ["li"]=> string(4) "LIKE" ["selected"]=> string(1) "f" } [3]=> array(3) { ["row_index"]=> int(4) ["li"]=> string(2) "IN" ["selected"]=> string(1) "f" } } ["lstpop_type"]=> string(1) "a" ["multi"]=> string(1) "f" ["size"]=> int(1) ["align"]=> string(6) "center" ["html"]=> string(0) "" } [2]=> array(7) { ["row_index"]=> int(3) ["eltype"]=> string(2) "tx" ["name"]=> string(9) "criteria1" ["lbl"]=> string(23) "enter_criteria_value(s)" ["align"]=> string(4) "left" ["size"]=> int(80) ["html"]=> string(0) "" } [3]=> array(5) { ["row_index"]=> int(4) ["eltype"]=> string(2) "ab" ["name"]=> string( "add_row1" ["lbl"]=> string(7) "add_row" ["html"]=> string(0) "" } [4]=> array(5) { ["row_index"]=> int(5) ["eltype"]=> string(2) "sb" ["name"]=> string(10) "submit_cri" ["lbl"]=> string(6) "submit" ["html"]=> string(0) "" } } Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 26, 2009 Share Posted September 26, 2009 From the moment I asked you to run modified code so I could see the array returned from the function until you actually posted the array, it took 9 posts. You said you didn't notice I modified your code, which tells me you are not reading my replies carefully. The modified code I used had a print_r(), you used var_dump(), which dumped out a ton of extra crap I didn't need to see. So you don't follow directions very well. Then when you post the output, you just plopped it into the post body and made no attempt to preserve the pretty output that var_dump() (and print_r()) both use. So I had to spend an extra 5 minutes fiddling around with your post to make a nice pretty output (that I think but am not sure) is the correct output from var_dump(). I don't have the time or patience to continue in this manner, so this is probably my last post in this thread. I suggest that when you request help from others in the future: 1) carefully read any replies 2) follow instructions 3) run any modified code (if it is safe to run (they might try to embed code that steals your database credentials for example)) 4) make information readable to others (unlike your post with the var_dump()) Anyways, after reformatting your post, var_dump() appears to look like this: array(5) { [0]=> array(11) { ["row_index"]=> int(1) ["eltype"]=> string(2) "ls" ["name"]=> string(7) "fldlst1" ["lbl"]=> string(12) "select_field" ["dflt"]=> string(0) "" ["lsttype"]=> string(1) "n" ["lstpop"]=> array(3) { [0]=> array(3) { ["row_index"]=> int(1) ["li"]=> string(10) "first_name" ["selected"]=> string(1) "f" } [1]=> array(3) { ["row_index"]=> int(2) ["li"]=> string(9) "last_name" ["selected"]=> string(1) "f" } [2]=> array(3) { ["row_index"]=> int(3) ["li"]=> string(5) "email" ["selected"]=> string(1) "f" } } ["lstpop_type"]=> string(1) "a" ["multi"]=> string(1) "f" ["size"]=> int(1) ["html"]=> string(0) "" } [1]=> array(12) { ["row_index"]=> int(2) ["eltype"]=> string(2) "ls" ["name"]=> string(6) "oplst1" ["lbl"]=> string(15) "select_operater" ["dflt"]=> string(1) "=" ["lsttype"]=> string(1) "n" ["lstpop"]=> array(4) { [0]=> array(3) { ["row_index"]=> int(1) ["li"]=> string(1) "=" ["selected"]=> string(1) "t" } [1]=> array(3) { ["row_index"]=> int(2) ["li"]=> string(2) "!=" ["selected"]=> string(1) "f" } [2]=> array(3) { ["row_index"]=> int(3) ["li"]=> string(4) "LIKE" ["selected"]=> string(1) "f" } [3]=> array(3) { ["row_index"]=> int(4) ["li"]=> string(2) "IN" ["selected"]=> string(1) "f" } } ["lstpop_type"]=> string(1) "a" ["multi"]=> string(1) "f" ["size"]=> int(1) ["align"]=> string(6) "center" ["html"]=> string(0) "" } [2]=> array(7) { ["row_index"]=> int(3) ["eltype"]=> string(2) "tx" ["name"]=> string(9) "criteria1" ["lbl"]=> string(23) "enter_criteria_value(s)" ["align"]=> string(4) "left" ["size"]=> int(80) ["html"]=> string(0) "" } [3]=> array(5) { ["row_index"]=> int(4) ["eltype"]=> string(2) "ab" ["name"]=> string( "add_row1" ["lbl"]=> string(7) "add_row" ["html"]=> string(0) "" } [4]=> array(5) { ["row_index"]=> int(5) ["eltype"]=> string(2) "sb" ["name"]=> string(10) "submit_cri" ["lbl"]=> string(6) "submit" ["html"]=> string(0) "" } } If I remove all the sub-array information, we are left with: array(5) { [0]=> array(11) { } [1]=> array(12) { } [2]=> array(7) { } [3]=> array(5) { } [4]=> array(5) { } } So your function is returning a numerically indexed (and thus not an associatively indexed) array. When we read the documentation on the extract() function: http://us.php.net/manual/en/function.extract.php Checks each key to see whether it has a valid variable name. Your keys are: 0, 1, 2, 3, 4 From elsewhere in the PHP documentation: A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' None of your keys are valid variable names so extract does not work. Which is what I predicted in my very first post: I'm guessing your array doesn't have any associative indexes. And if you had just followed directions, you would have had your answer two days ago and the problem would likely be solved by now. You could try something like calling extract on each element returned in the array, like so: $a = get_el_ary_cri(); foreach( $a as $v ) { extract( $v ); // do stuff here } But you will need to be careful in how you apply that because the sub-arrays have overlapping index names and will thrash the previous values in the symbol table. Quote Link to comment Share on other sites More sharing options...
venturemc Posted September 26, 2009 Author Share Posted September 26, 2009 Thanks for the lecture. Sorry I'm not perfect. But if you would take your own advise and read the posts caefully, you'd see that you may be looking for the wrong issue. I'm not having issue with the creation or use of the array. The exact same procedure is used many times throughout my script. For whatever reason, in THIS function, the return statement is failing to return the value to the calling script. Everything works fine if I pass it through a $_SESSION variable instead of using the return statement. This routine also worked fine when everything was in the same script - I just tried to make the routine portable which is why I broke the script into two pieces. That is when THIS function stopped completely working. I had been using a numerical index, but (possibly mistakenly so) thought I didn't need to as the array automatically creates an indexing system. I replaced it thinking that your observation pointed to a change I had made was something different than when it was working as one script. That did not correct the problem. I showed you what the function created (sorry it was ugly which is why I refrained from posting it in the first place) and thanks for taling the time to decode it. I'm not thinking that the result of the function is the issue (as I said, this exact process is working finr everywhere else in the script); if it returned an array that didn't work properly when retruned, then your angle would be worth looking into. I guess my most direct question would be: What would allow the variable to be passed via a $_SESSION pass vs. a function return call? 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.