PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I know in C there is the try/catch functions. I have been searching and appearently there is the same basic ability it PHP aswell. But I can't seem to get mine to work. It stops everything from working.
My code is as follows
i only see the text if i comment every try / catch
what do i have wrong with the try / catch portion. is there extra functions needed for it to work? or is there something else i need to do?
if
( // needs to test from here
$fExp = $fMult / $halfLife;
if ($fExp >= 11356.50) {
$fExp1 = 0.0;
} else {
if
{
$fExp1 = exp($fExp);
}
else
{
$fExp1 = 0.0;
}
}
$nCurrentActivity = $origActivity * $fExp1;
) {} // to here
else
{
$nCurrentActivity = 0.0; // if fail, do this
}
unless I am mistaken, then i need another solution. but if you can, then that would work perfectly
I know that the way I have it set up in my code does not work. How would I have to set it up for it to work (if it's possible)?
Yes, you can pretty much do anything with if/else. YOu will need to slightly restructure your logic, but I assure you it's possible. If you spell out the logic to me in english, I can tackle it for you.
If you refer the code in my first post, it is to calculate the half life (of a radioactive product) from a starting time to an end time. This may not neccessarily the full half life, thus the need for the calculation.
Example: productA's half-life = 2 years. you need 40 units 2 weeks from now. how much do you need to make now in-order to have exactly 40 in 2 weeks?
fairly common calculation. I am actually trying to convert it from C++ in to PHP
if it's just math, you could probably write something in JS to do it (and use try/catch).
if there's a possibility of it throwing errors, I'm not sure that if/else will suffice as it will only return booleans and errors don't fall within a boolean
I'd either upgrade php to 5 or do it with JS, and upon further reflection as I write this sentence, I'd do it with JS
I have been trying to do it in javascript, and it has been much more challenging that I thought. I don't know java nearly as well as i know PHP; and as far as I'm concerned, I don't know PHP all that well either, so that is saying a lot. But I have been working at it, and trying different functions to imitate some of those in php [such as explode() and the Date('U', $time) function]
If anyone knows of any good websites that gives a list of javascript commands (ie. http://www.php.net for php) That would be wonderful. everything i have found so far either gives a small portion of a few commands/topics or ellaborates in greate detail on a single command/topic, such as parseFloat().
as always, Thanks for you input and help.
That is a good idea, I think i will. Thank you very much.
You will probably see a post from on that section by the end of today.
Hopefull i can get what I need without doing so.
But I do appreciate the support.
Thank you everyone.