Inter-Dependant Variables in procedural application model
Posted on 2006-06-18
So I’m building a php loan application for my client. I’ve pretty much finished the entire app down to a problem with these 7 lines included below. I’m new at doing things that have so many interdependent variables and I am in a bit over my head at this point.
Basically what this thing does is takes a bunch of user input, sanitizes and validates it all then hands it off to this calculator. My approach was to take all of the formulas required to do the loan calculations and make a bunch of little functions that do little calculations and return values, arrays or sometimes print html out to the browser. Below all of the functions I instantiate all of the variables needed to do the loan calculations by making calls to the functions and interweave all of that with html and some logic to get everything done.
The problem is that I have a value, $ltv (below) that requires $estLoanCost to determine it’s value. $estLoanCost is not instantiated until further down the line. I have been moving things around (up or down) to make sure things happen in the right order. But this has boiled down to a kind of circular dependency between a handful of variables. I can’t move things around anymore without breaking more variables, I’ve basically boiled it all down to this. I can’t move $estLoanCost up because it requires everything above it to determine itself.
Right now this works because the ltv_func() is producing a value that allows the calculations to complete, but it does not use all of the right criteria in it’s decision making.
$ltv = ltv_func($nmdBal,$currentMortPayoffEst,$estLoanCost,$_SESSION['userHomeValue'],$ltvDeterminer);
$amtNewMort = amt_new_mort_func($ltv,$_SESSION['userHomeValue']);
$originationFee = origination_fee_func($amtNewMortA,$originationFeeDeterminer);
$titleCost = title_cost_func($amtNewMortA,$titleCostTable);
$escrowWaiverCost = round(escrow_waiver_cost($amtNewMort,$escrowWaiverDeterminer));
$interimInterest = round(interim_interest_func($amtNewMort,$interimRate));
$estLoanCost = est_loan_cost_func($originationFee,$hardCost,$titleCost,$escrowWaiverCost,$interimInterest);
So I think my problem is that I need a new paradigm for my approach of stitching all of this together. Is there a way I can have these run simultaneously? Doesn’t seem likely to me, but I’m definitely stumped as to how to get around this.
Any help would be greatly appreciated. My eyeballs hurt.