php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login go to bug id or search bugs for
Bug #26046 Submitted: Comparision operation fails 2003-10-30 20:48 UTC 2003-10-30 20:51 UTC richy at smilingsouls dot net Not a bug Math related 4.3.4RC3 Windows XP Home No None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !

[2003-10-30 20:48 UTC] 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 (\$LoanAllowance), 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 \$LoanAllowance variable.  However this appears to be overkill as \$LoanAllowance 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: http://p2p.wrox.com/topic.asp?TOPIC_ID=5869

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>
<!-- test.php -->
<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 />

<br />
<br />
<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='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);
\$LoanAllowance    = \$SalaryAllowance * \$AgeAllowance;

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

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

if (\$_POST["Loan"] <= \$LoanAllowance)

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

else if (\$_POST["Loan"] > \$LoanAllowance)

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

```

## History

```Sorry, but your problem does not imply a bug in PHP itself.  For a