ID: 26046
Updated by: [email]sniperphp.net[/email]
Reported By: richy at smilingsouls dot net
-Status: Open
+Status: Bogus
Bug Type: Math related
Operating System: Windows XP Home
PHP Version: 4.3.4RC3
New Comment:

Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit [url]http://www.php.net/support.php[/url] as this bug system is not the
appropriate forum for asking support questions.

Thank you for your interest in PHP.

Bogus example (too long), and there really is no bug here.



Previous Comments:
------------------------------------------------------------------------

[2003-10-30 20:48:00] richy at smilingsouls dot net

Description:
------------
In the following example from the Wrox Beginning PHP 4 textbook there
is a simple loan formula calculation. (This example has been altered to
accommodate register_globals = off and XHTML compliance)

When one enters an age of 23,
A salary of over 50,000
And a loan of 10,000

The loan application makes a few calculations and based on that input
should come up with a 'loan approval'.

However in the first conditional a comparison operation of less than or
equal to is performed between a string ($_POST["Loan"]) and a double
($Lolowance), the comparision fails and evaluates to false when it
is in fact true!

Here is an output of the code:

Namllu Credit Bank Loan Application Form

Loan wanted 10000
Loan amount we will allow: 10000

if (10000 <= 10000)
Sorry, Juan Valdez, we cannot accept your application at this time

The application prints out the values of each value being compared, 'if
(10000 <= 10000)' Obviously this should cause the first boolean
conditional to evaluate as true. 10000 is equal to 10000! We can see
here that the value printed is the expected result and not a result of
a syntax or logic error. In order to force this conditional statement
to evaluate as true (for this case) a ceil operation must be preformed
on the $Lolowance variable. However this appears to be overkill as
$Lolowance is not a decimal or fraction value and even if it were,
10000 is still equal to 10000!

This bug was first brought to my attention through the Wrox publishing
p2p forums. And the original thread may be viewed here:
[url]http://p2p.wrox.com/topic.asp?TOPIC_ID=5869[/url]

It appears to only present this problem when the user selects an age of
23. And to my knowledge it has been reproduced at least three times.

Reproduce code:
---------------
<html>
<head>
<!-- test.php -->
</head>
<body>
<span style='font-weight: bold;'>Namllu Credit Bank Loan Application
Form</span>
<form method='post' action='/test.php'>
First Name: <input name='FirstName' type='text' /><br />
Last Name: <input name='LastName' type='text' /><br />
Age: <input name='Age' type='text' size='3' />
<br /><br />

Address:
<textarea name="Address" rows='4' cols='40'></textarea>
<br />
<br />
What is your current salary?
<select name="Salary">
<option value='0'>Under $10000</option>
<option value='10000'>$10,000 to $25,000</option>
<option value='25000'>$25,000 to $50,000</option>
<option value='50000'>Over $50,000</option>
</select>
<br />
<br />
How much do you want to borrow?<br /><br />
<input name='Loan' type='Radio' value='1000'>Our $1,000 package at 8.0%
interest</input><br />
<input name='Loan' type='Radio' value='5000'>Our $5,000 package at
11.5% interest</input><br />
<input name='Loan' type='Radio' value='10000'>Our $10,000 package at
15.0% interest</input><br /><br />

<input type='submit' name='do_action' value='Click here to Submit
application' />
<input type='reset' value='Reset application form' />
</form>

<br />
<br />
<?php

if (isset($_POST["do_action"]))
{

echo "<span style='font-weight: bold;'>Namllu Credit Bank Loan
Application Form</span><br /><br />";

$SalaryAllowance = $_POST["Salary"] / 5;
$AgeAllowance = (($_POST["Age"] / 10 - ($_POST["Age"] % 10 ) /
10) -1);
$Lolowance = $SalaryAllowance * $AgeAllowance;

echo "Loan wanted {$_POST["Loan"]}<br />";
echo "Loan amount we will allow: $Lolowance<br /><br />";

echo "if ({$_POST["Loan"]} <= $Lolowance)<br />\n";

if ($_POST["Loan"] <= $Lolowance)

echo "Yes, {$_POST["FirstName"]} {$_POST["LastName"]}, we are
delighted to accept your application";

else if ($_POST["Loan"] > $Lolowance)

echo "Sorry, {$_POST["FirstName"]} {$_POST["LastName"]}, we
cannot accept your application at this time";

}
?>
</body>
</html>

Expected result:
----------------
(output from the php relevant portion)
Namllu Credit Bank Loan Application Form

Loan wanted 10000
Loan amount we will allow: 10000

if (10000 <= 10000)
Yes, Juan Valdez, we are delighted to accept your application

Actual result:
--------------
(output from the php relevant portion)
Namllu Credit Bank Loan Application Form

Loan wanted 10000
Loan amount we will allow: 10000

if (10000 <= 10000)
Sorry, Juan Valdez, we cannot accept your application at this time



------------------------------------------------------------------------


--
Edit this bug report at [url]http://bugs.php.net/?id=26046&edit=1[/url]