php - Sublime Text / code parse error for no reason, hidden characters -
i have had problem years, not today. prompted me ask question once , all.
sometimes (today every logic) trivial php code fails parse error. php right, way there no mistake , when writing exact same code again works without whining. copy , pasting code not work, has typed again in full.
today, have meticulously typed down every character line failing , removing old one, have script working. example:
1 foreach ($_post['data_positions'] $k => $v) { 2 3 }
threw parse error on line 1. bumped code down row 2 , wrote exact same line 1 again (i check several times every character same), removing line 2, , works. example:
1 if (is_numeric($k)) { 2 3 }
also fails on row 1. when retype it, works. copy , pasting line again not work.
i 100% code fine, leads me believe it's kind of encoding issue , parts of code attributed bad encoding (like pasting formatted text email).
i'm using sublime text (but have had same types of mistaken parse errors in notepad++ , old homesite editor well), running mamp on os x, has happened on windows desktop machine well.
does have clue can do? it's super annoying write code several times , having fail on randomly.
edit (reopened): still can't work properly. no matter if paste notepad or if type new file scratch. i've checked through database server editor use uft-8. it's if-statements break (sometimes have type them down 3 or 4 times before works. trivial stuff, if ($a === 3 || $a === 6) {}
.
edit (solved!): scroll down solution, answered question myself.
i found answer. had find out did wrong trial , error.
so, if code breaks due hidden characters, if find out character "Â" when switching iso-8859-1 utf-8, if it's happening in osx , in multiple editors (both sublime text , coda me) why:
in many operating systems non-breaking space instad of normal space when press alt+space
. many programming parsers (php, xcode example) fail when parsing character.
to fix in sublime text need edit preferences/key bindings - user , add line:
{ "keys": ["alt+space"], "command": "insert_snippet", "args": {"contents": " " } },
remember key bindings file array objects, , need keep ,
@ end if have more entries. remove if it's last one.
if need fix in other editor, google "youreditor disable alt space".
edit:
i noticed same behaviour alt+shift+space
, therefore added line keybinding config:
{ "keys": ["alt+shift+space"], "command": "insert_snippet", "args": {"contents": " " } },
:)
Comments
Post a Comment