From:             
Operating system: Linux
PHP version:      5.2.13
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Defaulting a class-function-param to 0 makes an IF see it as 
true when comparin

Description:
------------
Defaulting a class-function-param to 0 makes an IF see it as true when
comparing it to a string.



        function fillSelectBox($selected = 0)

        {

                $txt = '';



                $obj = new RetailerCountry();

                $objs = $obj->getAll();

                foreach ($objs as $ob)

                {

                        $id = $ob->getAttrib('retailercountry');

                        $name = $ob->getAttrib('retailercountry');



                        $txt .= $ob->getAttrib('retailercountry');



                        echo 'i:'.$id;

                        echo 's:'.$selected;



                        if ($id == $selected)

                        {

                                $txt .= ' * ';

                        }

                        $txt .= '<br>';

                }



                return $txt;

        }



The result for this function is: every word that's displayed gets a star
*.

This changes when I change the input param to $selected = ''.



But did or does PHP every care about this? I don't to do some kind of
strict typing!



Regards

MD



Test script:
---------------
        function fillSelectBox($selected = 0)

        {

                $txt = '';



                $obj = new RetailerCountry();

                $objs = $obj->getAll();

                foreach ($objs as $ob)

                {

                        $id = $ob->getAttrib('retailercountry');

                        $name = $ob->getAttrib('retailercountry');



                        $txt .= $ob->getAttrib('retailercountry');



                        echo 'i:'.$id;

                        echo 's:'.$selected;



                        if ($id == $selected)

                        {

                                $txt .= ' * ';

                        }

                        $txt .= '<br>';

                }

                return $txt;

        }



Expected result:
----------------
The result for this function is: every word that's displayed gets a star
*.

This changes when I change the input param to $selected = ''.



But did or does PHP every care about this? I don't to do some kind of
strict typing!


-- 
Edit bug report at http://bugs.php.net/bug.php?id=52265&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=52265&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=52265&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=52265&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=52265&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=52265&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=52265&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=52265&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=52265&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=52265&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=52265&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=52265&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=52265&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=52265&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=52265&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=52265&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=52265&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=52265&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=52265&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=52265&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=52265&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=52265&r=mysqlcfg

Reply via email to