{"id":1000291,"date":"2006-11-25T19:23:27","date_gmt":"2006-11-26T00:23:27","guid":{"rendered":"http:\/\/www.elharo.com\/blog\/software-development\/2006\/11\/25\/why-i-hate-weak-typing\/"},"modified":"2006-11-25T19:23:27","modified_gmt":"2006-11-26T00:23:27","slug":"why-i-hate-weak-typing","status":"publish","type":"post","link":"https:\/\/www.elharo.com\/blog\/software-development\/2006\/11\/25\/why-i-hate-weak-typing\/","title":{"rendered":"Why I hate weak typing"},"content":{"rendered":"<p>I just wasted at least two hours hunting down a bug that turned out to be in this PHP code fragment:<\/p>\n<pre><code>      if ($reader->hasValue) {\r\n        echo \": \" + $reader->value;\r\n      }\r\n<\/code><\/pre>\n<p>Do you see the bug?<br \/>\n<!--more--><\/p>\n<p>The problem is that I&#8217;m using the arithmetic addition operator <code>+<\/code> instead of the string concatenation operator <code>.<\/code>. If PHP were more strongly typed it would have complained about my attempt to concatenate two strings using a purely numeric operator. Instead it silently converted each string to a number (I&#8217;m not sure exactly <a href=\"http:\/\/us2.php.net\/manual\/en\/language.types.string.php\">how<\/a>), added those numbers, and echoed the resulting integer. <\/p>\n<p>It didn&#8217;t help that I wasn&#8217;t very experienced with the API I was using so I didn&#8217;t initially realize that the almost plausible output I was getting was a result of my bug and not some weirdness in the library. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just wasted at least two hours hunting down a bug that turned out to be in this PHP code fragment: if ($reader->hasValue) { echo &#8220;: &#8221; + $reader->value; } Do you see the bug?<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[410],"class_list":["post-1000291","post","type-post","status-publish","format-standard","hentry","category-software-development","tag-flash"],"_links":{"self":[{"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/posts\/1000291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/comments?post=1000291"}],"version-history":[{"count":0,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/posts\/1000291\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/media?parent=1000291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/categories?post=1000291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/tags?post=1000291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}