Bug when creating new PHP file

PHP Tools [?] extends Visual Studio with set of advanced features to work more efficiently with PHP code.

Bug when creating new PHP file

Postby fantasticjamieburns » March 13th, 2013, 6:20 pm

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.
You do not have the required permissions to view the files attached to this post.
fantasticjamieburns
 
Posts: 44
Joined: September 10th, 2012, 10:33 am

Re: Bug when creating new PHP file

Postby Jakub Misek » March 14th, 2013, 12:18 am

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!
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: Bug when creating new PHP file

Postby codeowl » March 18th, 2013, 5:36 am

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
codeowl
 
Posts: 51
Joined: February 10th, 2013, 10:05 am

Re: Bug when creating new PHP file

Postby Jakub Misek » March 24th, 2013, 7:44 pm

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...)
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: Bug when creating new PHP file

Postby codeowl » March 25th, 2013, 6:48 am

Jakub,

Great work getting onto this so quickly mate ;-)

Regards,

Scott
codeowl
 
Posts: 51
Joined: February 10th, 2013, 10:05 am


Return to PHP Tools

Who is online

Users browsing this forum: No registered users and 45 guests

cron

User Control Panel

Login

Who is online

In total there are 45 users online :: 0 registered, 0 hidden and 45 guests (based on users active over the past 5 minutes)
Most users ever online was 256 on March 28th, 2024, 9:42 am

Users browsing this forum: No registered users and 45 guests