|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-07-06 17:17 UTC] johannes@php.net
-Status: Open
+Status: Bogus
[2010-07-06 17:17 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 26 07:00:01 2025 UTC |
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!