Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

A look into the high-level programming operations for the PHP language

Save for later
  • 3 min read
  • 11 Mar 2013

article-image

(For more resources related to this topic, see here.)

Accessing documentation

PhpStorm offers four different operations that will help you to access the documentation: Quick Definition, Quick Documentation, Parameter Info, and External Documentation. The first one, Quick Definition, presents the definition of a given symbol. You can use it for a variable, function, method, or class. Quick Documentation allows easy access to DocBlocks. It can be used for all kinds of symbols: variables, functions, methods, and classes. The next operation, Parameter Info, presents simplified information about a function or method interface. Finally, External Documentation will help you to access the official PHP documentation available at php.com.

Their shortcuts are as follows:

  • Quick Definition (Ctrl + Shift + I, Mac: alt + Space bar)

  • Quick Documentation (Ctrl + Q, Mac: F1)

  • Parameter Info (Ctrl + P, Mac: command + P)

  • External Documentation (Shift + F1, Mac: shift + F1)

The Esc (Mac: shift + esc) hotkey will close any of the previous windows.

If you place the cursor inside the parenthesis of $s = str_replace(); and run Parameter Info (Ctrl + P, Mac: command + P), you will get the hint showing all the parameters for the str_replace() function. If that is not enough, place the cursor inside the str_replace function name and press Shift + F1 (Mac: shift + F1). You will get the manual for the function.

If you want to test the next operation, open the project created in the Quick start – your first PHP application section and place the cursor inside the class name Controller in the src/My/HelloBundle/Controller/DefaultController.php file. The place where you should place the cursor is denoted with bar | in the following code:

class DefaultController extends Cont|roller { }

The Quick Definition operation will show you the class definition:

look-high-level-programming-operations-php-language-img-0

The Quick Documentation operation will show you the documentation defined with PhpDoc blocks:

look-high-level-programming-operations-php-language-img-1

It is a formal standard for commenting on the PHP code. The official documentation is available at http://www.phpdoc.org.

Generators

PhpStorm enables you to do the following:

  • Implement magic methods

  • Override inherited methods

  • Generate constructor, getters, setters, and docblocks

    Unlock access to the largest independent learning library in Tech for FREE!
    Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
    Renews at ₹800/month. Cancel anytime

All of these operations are available in Code | Generate (Alt + Insert, Mac: command + N). Perform the following steps:

  1. Create a new class Foo and place the cursor at the position of | :

    class Person { | }

  2. The Generate dialog box will contain the following operations:

    look-high-level-programming-operations-php-language-img-2

    The Implement Methods dialog box contains all available magic methods:

    look-high-level-programming-operations-php-language-img-3

  3. Create the class with two private properties:

    class Lorem { private $ipsum; private $dolor; }

  4. Then go to Code | Generate | Getters and Setters. In the dialog box select both properties:

    look-high-level-programming-operations-php-language-img-4

  5. Then press OK. PhpStorm will generate the following methods:

    class Lorem { private $ipsum; private $dolor; public function setDolor($dolor) { $this->dolor = $dolor; } public function getDolor() { return $this->dolor; } public function setIpsum($ipsum) { $this->ipsum = $ipsum; } public function getIpsum() { return $this->ipsum; } }

  6. Next, go to Code | Generate | DocBlocks and in the dialog box select all the properties and methods:

    look-high-level-programming-operations-php-language-img-5

  7. PhpStorm will generate docblocks for each of the selected properties and methods, for example:

    /** * @param $dolor */ public function setDolor($dolor) { $this->dolor = $dolor; }

Summary

We just learned that in some cases you don't have to type the code at all, as it can be generated automatically. Generators discussed in this article lifted the burden of type setters, getters and magic functions from your shoulders. We also dived into different ways to access documentation here.

Resources for Article :


Further resources on this subject: