Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make better use of the automatic prompt of PHPstorm by PHP

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces PHP how to make better use of the automatic prompt of PHPstorm, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

What are the characteristics of php 1, the execution speed is fast. 2. It has good openness and expansibility. 3. PHP supports a variety of mainstream and non-mainstream databases. Object-oriented programming: PHP provides classes and objects. 5. The update speed of the version is fast. 6. It has rich functions. 7. Scalability. 8. Comprehensive functions, including graphics processing, encoding and decoding, compressed file processing, xml analysis and so on.

How to make better use of the automatic prompt of PHPstorm by PHP

Description

After writing java for a period of time, I am not used to the weakly typed way of PHP itself, and I always feel uneasy when writing code, especially when PHP is a weakly typed language, so when coding, there are often no code hints.

A general example class Data {public $name; public $gender; public $age; public function _ _ construct ($name,$gender,$age) {$this- > name = $name; $this- > gender = $gender; $this- > age = $age }} class Test {public function run () {$data = [new Data ('Zhang San', 'male', 18), new Data ('Li Si', 'male', 14), new Data ('Wang Wu', 'male', 17), new Data ('period', 'female', 23)] } private function eachData ($data) {foreach ($data as $item) {echo $item- > name.'= >'. $item- > gender.'= >'. $item- > age. "\ n";} (new Test)-> run ()

From the above example, generally speaking, there is no problem, but in writing

Cho $item- > name.'= >'. $item- > sex.'= >'. $item- > age. "\ n"

When this code is called, there is no automatic prompt when calling the attribute, so when there is a large amount of data, you need to flip it up and then copy or write it down to slow down the coding speed, and sometimes you don't have the spectrum in mind for fear of writing mistakes.

Here is an example I wrote of a complete use of annotations and their own PHP features:

Class Data {public $name; public $gender; public $age; public function _ _ construct ($name,$gender,$age) {$this- > name = $name; $this- > sex = $gender; $this- > age = $age }} class Test {public function run () {$data = [new Data ('Zhang San', 'male', 18), new Data ('Li Si', 'male', 14), new Data ('Wang Wu', 'male', 17), new Data ('period', 'female', 23)] } / * traversal output data * @ param array $data * / private function eachData ($data) {foreach ($data as $item) {if ($item instanceof Data) {echo $item- > name.'= >'. $item- > gender.'= >'. $item- > age. "\ n";} (new Test)-> run ()

The main thing here is to add an if judgment to determine whether the data type is a concrete example of Data.

In this place, according to this judgment, PHPstorm will automatically prompt when making the $item attribute call, which is very convenient.

Thinking

Some thinking from here is that we can better consider rigor when writing programs, and from the above example, if we do it this way, plus some error handling mechanisms, it can better ensure the security and integrity of the data, not just the convenience of the editor prompt.

It will also be very convenient to do code review and tracking later, and the business logic will be clearer.

Thank you for reading this article carefully. I hope the article "how to make better use of the automatic hints of PHPstorm" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report