Bug when creating new PHP file
5 posts
• Page 1 of 1
Bug when creating new PHP file
Hey,
When I create a new PHP script by right clicking on the file tree and using the menu:
Add -> Add New Item
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.
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.
When I create a new PHP script by right clicking on the file tree and using the menu:
Add -> Add New Item
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
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!
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. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: Bug when creating new PHP file
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!!
Regards,
Scotty
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!!
Regards,
Scotty
- codeowl
- Posts: 51
- Joined: February 10th, 2013, 10:05 am
Re: Bug when creating new PHP file
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. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: Bug when creating new PHP file
Jakub,
Great work getting onto this so quickly mate
Regards,
Scott
Great work getting onto this so quickly mate
Regards,
Scott
- codeowl
- Posts: 51
- Joined: February 10th, 2013, 10:05 am
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 92 guests