Edit report at http://bugs.php.net/bug.php?id=52265&edit=1

 ID:               52265
 Updated by:       johan...@php.net
 Reported by:      weer1 at gmx dot net
 Summary:          Defaulting a class-function-param to 0 makes an IF see
                   it as true when comparin
-Status:           Open
+Status:           Bogus
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: Linux
 PHP Version:      5.2.13

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

See http://php.net/manual/en/types.comparisons.php


Previous Comments:
------------------------------------------------------------------------
[2010-07-06 16:42:20] weer1 at gmx dot net

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 this bug report at http://bugs.php.net/bug.php?id=52265&edit=1

Reply via email to