I can't believe that I didn't find an already asked question to that topic (maybe I am wrong). However, for example in WordPress-Themes all PHP-files come with a comment header block:
<?php
/**
* Template for header
*
* Description
*
* #Author: Mokorana
* #Date: 2020-11-26 09:19:12
* #Last Modified by: Mokorana
* #Last Modified time: 2020-11-27 10:08:51
*
* #package mokorana
*/
?>
Whats is the best practice to add and maintain these comment blocks? Is it done directly in the text editor (atom) or in a node-workflow or however?
Adding header comments it's usually automated process.
The simplest way is to configure header comment for each new PHP file in your IDE. For example PhpStorm has File templates for this.
Another option these are tools like PHP CS Fixer. You configure header comment template and add it to all files in your project using one simple command.
Tools like PHP CS Fixer it's a better way, because if you want to change something in your comment, you just need to update template in config file and run console command again. It will update all files in your project.
Related
When I write in a php file the following:
<?php
/**
* Comments....
the VSCode autoformat on save like this:
<?php
/**
* Comments....
I don't want this auto empty newline.
The "problem" is detected only after the combination of <?php and /** comments.
Thank you
not sure how to really say this in a completely understandable way, but you need to edit the formatter configuration that you use in vscodes settings. Or you can install a different formatter and use that instead with its own config
Let's say I can see list of files available on server. check the attached screens shot. Any way to check the file content as well? (assume listing from live site)
I'm sorry for the method I used to answer this question. I received errors about code indent by 4 spaces but my answer was well formed however I was not able to post my answer due to bugs in the Stack Overflow system.. I added a screenshot to this answer with my original answer included (Screenshot from answer example) and hope my answer is still useful. I didn't contact Stack Overflow staff as this is a known issue.. see also this question and others wich are about similar issues.
My answer (Screenshot / Screencapture)
As I were not able to put the code in separated code blocks I put them all in 1 code block only, please see the screenshot above to understand the numbers, Code 1 is the first code block in the image, code 2 is the second code you'll find on the screenshot etc... The screenshot has been edited, I added code block numbers to the picture..
/** Code 1 **/
<?php // This can be used in a file that should be included to an other file
if(!defined('NO_CONTENT_AVAILABLE')) {
die('This file cannot be accessed directly!<br /><br />Something went wrong and the content is out for a walk...'); /** Do not change it's a text for users who visit this document... **/
}
/** Your content for tthe file below this line **/
?>
/** Code 2 **/
<?php
define('NO_CONTENT_AVAILABLE',1); /** You'll need this line on top OR above the line where you'll use the file that require NO_CONTENT_AVAILABLE to be defined **/
include $_SERVER['DOCUMENT_ROOT'] . '/path/to/your/file.php'; /** the file that require NO_CONTENT_AVAILABLE to be defined **/
?>
/** Code 3 **/
Options -Indexes
/** Code 4 **/
<RequireAll>
Require ip 178.221.255.121 2a02:a430:fe83:1:ca:4240:2e0:16 192.168.150.254
</RequireAll>
All other IP adresses cannot open the directory and will receive status code 403 FORBIDDEN or other status depending on your configuration
The files should be accessible by your visitors but you do not need the listings as the files should not be accessed directly. This said there are only two options in my answer that fit your needs:
Update all files where it's needed with the php code above that will deny direct access, to add define anddefinedto all of your files will be a lot of work as you need to edit a lot of files...
add Options -Indexes to your .htaccess file
Use both of the above options wich is what I do on custom coded websites. even if you don't show indexes, the files still can be accessible in any webbrowser and that's why you might want to use both of the above options ...
I hope I was able to offer the information you need and that this answer will bring you into the right direction.
the form of comment block for php in sublime-text looks like this.
/ * Example * /
I would like to change it to look like that.
/**
* example
**/
I try to modify the file in Comments.tmPreferences Package / php / but I'm not coming. I do not understand the xml use.
I know it is not much, but just personal choice.
Use sublime-jsdocs
install the package, and you should be able to make docblock comments.
By Pressing enter or tab after /** (or ###* for Coffee-Script) will yield a new line and will close the comment.
With Package Control installed, you can install DocBlockr from inside Sublime Text itself. Open the Command Palette and select "Package Control: Install Package", then search for DocBlockr and you're done!
you can do this:
(Docblock completion)
(Comment extension)
or this:
When I'm coding using PHP in Vim I can create a comment block like this:
/**
* Mary had a little lamb.|
*/
When my cursor | is at the end of the sentence, I press return and get a new comment line this:
/**
* Mary had a little lamb.
* |
*/
Notice it has automatically added a new * character to continue the comment.
When I program using D in Vim and try the same thing, there is no new * added automatically and I get this:
/**
* Mary had a little lamb.
|
*/
Where do I need to add this in the D configuration to copy the PHP auto-complete of the comments?
Take a look at :h formatoptions and :h fo-table. The option you're looking for is r:
Automatically insert the current comment leader after hitting
Enter in Insert mode.
You can create a file called d.vim in ftplugin in your vimfiles directory (where that is depends on your OS) and put your custom set formatoptions line there.
Take a look at this section specifically, but this whole wiki page should have a lot of useful information. http://vim.wikia.com/wiki/Indent
File type based indentation
This type of indentation is the most
flexible, as it allows users to customize indentation per file type.
For instance, the indentation scripts for C and C++ file types
properly set the 'cindent' option, and there are very competent
indentation scripts for Ruby, Perl and many other languages and file
types. File type based indentation even works correctly with Makefiles
without interference! If you plan on using file type based
indentation, don't set 'smartindent' or 'cindent'. You may still set
'autoindent', since it doesn't interfere.
The vimrc_example.vim that ships with Vim enables filetype based
indentation:
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" ...
endif
How can I add comments in PHP eclipse? I'm trying by selecting few lines of code, then right click, On menu, "Source" and then I have tried all these options there "general element comment", "toggle comment", "Add block comment". None of them works.
PS. I just downloaded latest eclipse PHP version.
Try Ctrl+Shift+/
The question is similair to How to comment a block in Eclipse?
Why don't you just try adding /** + enter? It will produce something like
/**
* Comment here
*/
Remember to follow the doc order
/**
* Description
* #param argument/parameter
* #return
*/
It`s a bug in latest PHP eclipse. Fix is here.
I was using single line comments on my eclipse php project. When i uploaded it to server ,some obfuscation has been applied automatically.Hence all the line breaks are removed and it treating the whole program as a single line. so i am getting an END OF STATEMENT error on server.So its better to use /--/ instead of //---- while commenting.