Page 1 of 1

Bug when creating new PHP file

PostPosted: March 13th, 2013, 6:20 pm
by fantasticjamieburns
Hey,

When I create a new PHP script by right clicking on the file tree and using the menu:

Add -> Add New Item

AddNewItem.png


The PHP file that gets created looks correct, but is in fact corrupted and will result in a Fatal Error if used with a namespace declaration statement.

Code: Select all
Fatal error: Namespace declaration statement has to be the very first statement in the script in C:\Whatever.php on line 3


Of course namespace certainly is the first statement!

What appears to be happening is the file is created as:

UTF8+BOM
http://en.wikipedia.org/wiki/Byte_order_mark

The BOM is making PHP think some output has taken place, and therefore the namespace declaration statement is not allowed. This has been happening for a couple of months and is not related to the recent release.

My solution has been to open the file in EditPlus and convert the file to regular UTF8 without a BOM.

Re: Bug when creating new PHP file

PostPosted: March 14th, 2013, 12:18 am
by Jakub Misek
Hi,

You are right, there is BOM at the beginning of default PHP Script item template.

You can change the encoding of single file in VS itself (File -> Advanced Save Options ...).

However this is probably not optimal encoding for PHP files. For now you can create own Item Template:
- create file with your encoding, and content
- File -> Export Template -> Item Template

We will improve this in a future update.

Thanks!

Re: Bug when creating new PHP file

PostPosted: March 18th, 2013, 5:36 am
by codeowl
FantasticJamieBurns,

Great work finding the cause of this one mate!!

Thanks for posting on the forum ;-)

I have the same problem with namespaces. I can't imagine how I would have worked out it was the file encoding!! :shock:

Regards,

Scotty

Re: Bug when creating new PHP file

PostPosted: March 24th, 2013, 7:44 pm
by Jakub Misek
Latest update http://visualstudiogallery.msdn.microso ... 5f50c95fb5 removes BOM from new PHP script files. Just noting this causes encoding of the new file to fallback to current windows locale. When using non-ascii characters in the file and you want to use UTF8, you have to set the encoding manually (File -> Advanced Save Options...)

Re: Bug when creating new PHP file

PostPosted: March 25th, 2013, 6:48 am
by codeowl
Jakub,

Great work getting onto this so quickly mate ;-)

Regards,

Scott