PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 30, 2022

[FIXED] what is the purpose of the extra asterisks in php comments?

 August 30, 2022     comments, pear, php, standards     No comments   

Issue

I've (finally) been reading up on PEAR (php) coding standards.

What is the purpose of commenting like this:

/** 
*   Here is my comment
*   I Wrote this in a haiku
*   But why put the stars?
*/

As opposed to this:

/* 
   Here is a comment
   No haiku or 
   anything special, but it still works!
*/

Solution

The /** stuff */ document is also referred to as DocBlock notation.

It's used to document PHP functions, classes, etc.

/** 
* A test function
*
* @param  foo $bar
* @return baz
*/
function test(foo $bar) { return new baz; }

Some editors make good use of this to perform their Code Insight feature, a very powerful tool that reduces the time you have to spend looking at your old function declarations. Aptana and Zend Studio have this feature, probably others as well.

You can also use it in combination with Reflection to do some sort of AOP, doing runtime inspection of the DocBlock above your declarations. In fact, Doctrine uses it to build an object attribute map for their "Active Record" implementation.



Answered By - Ja͢ck
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing