From:
Operating system: CentOS 5.5
PHP version: 5.3.2
Package: Unknown/Other Function
Bug Type: Bug
Bug description:Passing "0" as a parameter through a custom method
Description:
------------
Sorry but I didn't know how to best word the summary.
I have a custom method with an if statement inside. If the parameter passed
through matches "Test", a string is echo'ed. However if I pass "0" through
as the parameter, PHP thinks this is "Test" and echoes the string.
Passing a blank parameter through, i.e. "", does not have the same effect
as "0".
Inserting "if (empty($str))" before the if statement in the example works
as expected, catches the "0" parameter and I get the expected result.
However without this, I get the actual result.
All plugins have been disabled and Apache restarted.
Test script:
---------------
<?php
function testMethod($str = 0)
{
if ($str == 'Test')
{
echo 'Test String!<br>';
}
}
testMethod('Test');
testMethod(0);
testMethod();
testMethod(1);
testMethod('Something');
?>
Expected result:
----------------
Test String!
Actual result:
--------------
Test String!
Test String!
Test String!
--
Edit bug report at http://bugs.php.net/bug.php?id=52031&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=52031&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=52031&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=52031&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=52031&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=52031&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=52031&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=52031&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=52031&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=52031&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=52031&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=52031&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=52031&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=52031&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=52031&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52031&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=52031&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=52031&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=52031&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=52031&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=52031&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=52031&r=mysqlcfg