How does PHP make use of the automatic prompt of PHPstorm
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.