{"id":1614,"date":"2013-02-26T00:00:00","date_gmt":"2013-02-25T23:00:00","guid":{"rendered":"https:\/\/wwwneu.strehle.de\/tim\/weblog\/archives\/2013\/02\/26\/1563\/"},"modified":"2013-02-26T00:00:00","modified_gmt":"2013-02-25T23:00:00","slug":"1563","status":"publish","type":"post","link":"https:\/\/www.strehle.de\/tim\/weblog\/archives\/2013\/02\/26\/1563\/","title":{"rendered":"Non-breaking space accidentally typed in OS X kills PHP code? Use Karabiner"},"content":{"rendered":"<p>I finally found a solution to a problem that has bugged me for years:<\/p>\n<p>When editing PHP source code on my Mac, the code would occasionally break completely with an error message like \u201cPHP Fatal error: Cannot use [] for reading in \u2026 on line \u2026\u201d. The code on that line would look completely fine in the editor, say: \u201c$a[] = 1;\u201d<\/p>\n<p>Only when I\u2019d switch on \u201cShow Invisibles\u201d in TextWrangler, I\u2019d see some funny bullet in front of the equals sign. What looked like a regular space character was actually a non-breaking space (Unicode U+00A0, officially called \u201cNo-Break Space\u201d, \u201cc2 a0\u201d in a UTF-8 file\u2019s hexdump).<\/p>\n<p>It was inserted because I typed to fast (or too sloppily); I had been hitting the space bar while the Alt key was still pressed. (This wouldn\u2019t happen on a standard US keyboard, but the German keyboard layout requires the Alt key for typing square [ ] and curly brackets { }.)<\/p>\n<p>The superuser article <a href=\"http:\/\/superuser.com\/questions\/78245\/how-to-disable-the-option-space-key-combination-for-non-breaking-spaces\">How to disable the Option-Space key combination for non-breaking spaces?<\/a> had the solution: Install the free <a href=\"https:\/\/pqrs.org\/osx\/karabiner\/\">Karabiner (formerly named KeyRemap4MacBook)<\/a> (requires a reboot), search for \u201coption+space\u201d in its preferences and check the \u201cNon-Breaking Space to Normal Space\u201d option.<\/p>\n<p><span class=\"italic\"><em>Update:<\/em> KeyRemap4MacBook has been renamed to Karabiner. And here\u2019s a <a href=\"https:\/\/gist.github.com\/tistre\/40277b47155b7f5a678c\">PHP script to find non-breaking spaces<\/a> in your source code.<br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I finally found a solution to a problem that has bugged me for years: When editing PHP source code on my Mac, the code would occasionally break completely with an error message like \u201cPHP Fatal error: Cannot use [] for reading in \u2026 on line \u2026\u201d. The code on that line would look completely fine [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_share_on_mastodon":"0"},"categories":[1],"tags":[],"class_list":["post-1614","post","type-post","status-publish","format-standard","hentry","category-weblog"],"share_on_mastodon":{"url":"","error":""},"_links":{"self":[{"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/posts\/1614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/comments?post=1614"}],"version-history":[{"count":0,"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/posts\/1614\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/media?parent=1614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/categories?post=1614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/tags?post=1614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}