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

Exclusive offer: get 50% off this eBook here
Instant PhpStorm Starter [Instant]

Instant PhpStorm Starter [Instant] — Save 50%

Learn professional PHP development with PhpStorm book and ebook

$14.99    $7.50
by Włodzimierz Gajda | March 2013 | PHP

PhpStorm offers large number of high-level programming operations that will help you to write and inspect the PHP code. The following list provides a few examples of such operations:

  • Accessing documentation

  • Generating code

  • Generating class diagrams

  • Autoformatting

  • Inspections

This article by Wlodzimierz Gajda, author of Instant PhpStorm Starter, will give you an insight into the high-level programming operations of accessing documents and generating code.

(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:

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

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

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:

    The Implement Methods dialog box contains all available magic methods:

  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:

  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:

  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:


Instant PhpStorm Starter [Instant] Learn professional PHP development with PhpStorm book and ebook
Published: February 2013
eBook Price: $14.99
See more
Select your format and quantity:

About the Author :


Włodzimierz Gajda

Włodzimierz Gajda is a very experienced lecturer and a highly passionate teacher. During the last twenty years, he conducted numerous classes and courses on very diverse subjects, from programming in C language and TCP/IP networking, to building LEGO robots and developing web applications with PHP.

His teaching and learning activities for the last ten years have been concentrating around web development and web design. He currently works in the Institute of Mathematics and Computer Science at The Catholic University of Lublin, where he teaches web development, programming in PHP, and web design.

Włodzimierz occasionally contributes to open source projects on Github (https://github.com/gajdaw) and regularly writes books for Helion, the largest IT publishing house in Poland. He has published 12 books including:

• GIMP. Practical projects
• HTML, XHTML and CSS. Practical projects
• PHP. Practical projects
• jQuery for programmers
• Symfony by examples
• Zend Framework from scratch
• Git. Distributed Version Control System

Tatra mountains trekking, playing blues (http://www.youtube.com/user/gajdaw), and reading horrors are his preferred leisure activities.

Visit Włodzimierz at http://gajdaw.pl.

Books From Packt


Learning PHP Data Objects
Learning PHP Data Objects

PHP Oracle Web Development: Data processing, Security, Caching, XML, Web Services, and Ajax
PHP Oracle Web Development: Data processing, Security, Caching, XML, Web Services, and Ajax

Expert PHP 5 Tools
Expert PHP 5 Tools

Backbase 4 RIA PHP 5 Social Networking
PHP 5 Social Networking

Building Websites with PHP-Nuke
Building Websites with PHP-Nuke

Web Application Development with Yii and PHP
Web Application Development with Yii and PHP

 Yii 1.1 Application Development Cookbook
Yii 1.1 Application Development Cookbook

Agile Web Application Development with Yii1.1 and PHP5
Agile Web Application Development with Yii1.1 and PHP5


Your rating: None Average: 1 (1 vote)

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
V
m
2
2
2
Q
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software