In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you the content of automatic tips on how PHP uses PHPstorm. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
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 is the end of the automatic tips on how PHP uses PHPstorm. I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.