Ok, here s the deal where I m really stuck.
I use my cms with design patterns. Where s the last final output(in design template s main file: design.php ):
<div>{CONTENT_HEADER}</div>
<div style= float:left;width:25% >{CONTENT_LEFT}</div>
<div style= float:left;width:50% >{CONTENT_CENTER}</div>
<div style= float:left;width:25% >{CONTENT_RIGHT}</div>
<div>{CONTENT_FOOTER}</div>
Where is CONTENT_XXXX is generater thought site modules:
ob_start("gz_handler");
<....... LOAD ALL THE HEADER MODULES .......>
$output0 = ob_get_contents();
ob_end_clean();
ob_start("gz_handler");
<....... LOAD ALL THE LEFT SIDE MODULES .......>
$output1 = ob_get_contents();
ob_end_clean();
ob_start("gz_handler");
<....... LOAD ALL THE CENTER SIDE MODULES .......>
$output2 = ob_get_contents();
ob_end_clean();
ob_start("gz_handler");
<....... LOAD ALL THE RIGHT SIDE MODULES .......>
....
// That s I talk about, but this is just for static html, not variables
// Push to header finalizers to override default <title></title>
$header_finalizers_array[ change_head_title_attr_to ] = $thread_data[ topic_title ];
<....... END OF ALL THE RIGHT SIDE MODULES .......>
$output3 = ob_get_contents();
ob_end_clean();
ob_start("gz_handler");
<....... LOAD ALL THE FOOTER MODULES .......>
$output5 = ob_get_contents();
ob_end_clean();
define("CONTENT_HEADER", finalize_output($output0,$header_finalizers_array));
define("CONTENT_LEFT", finalize_output($output2,$left_finalizers_array));
define("CONTENT_CENTER", finalize_output($output3,$center_finalizers_array));
define("CONTENT_RIGHT", finalize_output($output4,$right_finalizers_array));
// No need finalizations, because there are no more parts, which call content changes
define("CONTENT_FOOTER", $output5);
All is ok in 95% of cases. But, there are some cases, where I need TO GET THE CONTENT OF VARIABLE(in left side modules) which ONLY will be defined in NEXT SIDE(ex. in right side modules)
With my code, I can define the site headers in header modules , but then if I want that, I m able to change it in ex. right side, because I m able add to array the replace data requirement, which will be executed after all the side content will be generater to variables but BEFORE printing in to client browser.
All this could be done only with 1 line in function:
function finalize_output($output="",$fin_array=array()) {
<...>
$output = preg_replace("#<title>.*</title>#i", "<title>".$fin_array[ change_head_title_attr_to ]."</title>", $output, 1);
<...>
}
Now about my problem.
How to do the same with VARIABLES:
IN LEFT SIDE modules I have a sentence (PROBLEM: $object ):
if(isset($object)) {
$best_product = sqlArray(sqlQuery("SELECT * FROM tableA WHERE b= $object "));
<..All the rest code of BEST s product..>
}
IN RIGHT SIDE modules I have the sencence (PROBLEM: $object ):
<... Print LAST 10 PRODUCTS ***>
$res = sqlquery("SELECT * FROM tableA ORDER BY id DESC LIMIT 100);
while($data = sqlarray($res)) { <..PRINT PRODUCT INFO..> }
$new = rand(0,secured($_POST[ user_input_new_products ]));
for($i=1;$i<=$new;$i++) {
$price_diff_old_new1 = change_products_to_sql( fish_$i , 19.99);
$price_diff_old_new2 = push_product_to_sql( crab_$i , 16.99);
if($i==$new) {
$object = $price_diff_old_new1+$price_diff_old_new2;
}
}
THIS IS JUST EXAMPLE CODE OF WHAT I NEED TO DO(so don t go to details), but THE POINT IS THAT, that I need somehow to submit the variable to earlier point of source: One of solutions would be " USE GOTO ", but is it variable will be remebered.
I mean:
echo "JOB IS STARTED";
LABEL HOME:
<INCLUDED FILE : procuts.php >
if(isset($object) && check_is_number($object)) {
$a = $object;
}
if(isset($break_me) && $break_me) {
GOTO FINAL;
}
<END OF INCLUDE>
...
<INCLUDED FILE : upload.php >
$object = 999;
$break_me = true;
GOTO HOME;
<END OF INCLUDE>
}
LABEL FINAL:
echo "JOB IS DONE";
AND, is there are any other way to do this WITHOUT GOTO(if GOTO solution is possible(?)) ?
I personally thought that is not possible to code it, but since Php 5.3.0 it is possible, I become likely to be coded. Misfortunelly I m not sure the company will use Php 5.3.0 on their servers, so I hope there is another solutions.
Also I m still not sure even the GOTO will help there.