1 | <?php |
||
21 | class Webservices |
||
22 | { |
||
23 | public $json; |
||
24 | public $std; |
||
25 | |||
26 | /** |
||
27 | * Constructor |
||
28 | * @param string $xml path or xml content from |
||
29 | * nfe_ws3_mod55 |
||
30 | */ |
||
31 | 1 | public function __construct($xml) |
|
35 | |||
36 | /** |
||
37 | * Get webservices parameters for specific conditions |
||
38 | * the parameters with the authorizers are in a json file in |
||
39 | * the storage folder |
||
40 | * @param string $sigla |
||
41 | * @param string $ambiente "homologacao" ou "producao" |
||
42 | * @param string $modelo "58" |
||
43 | * @return boolean | \stdClass |
||
44 | */ |
||
45 | 1 | public function get($sigla, $ambiente, $modelo) |
|
67 | |||
68 | /** |
||
69 | * Return WS parameters in a stdClass |
||
70 | * @param string $xml |
||
71 | * @return \stdClass |
||
72 | */ |
||
73 | 1 | public function toStd($xml = '') |
|
80 | |||
81 | /** |
||
82 | * Return WS parameters in json format |
||
83 | * @return string |
||
84 | */ |
||
85 | public function __toString() |
||
89 | |||
90 | /** |
||
91 | * Read WS xml and convert to json and stdClass |
||
92 | * @param string $xml |
||
93 | */ |
||
94 | 1 | protected function convert($xml) |
|
111 | |||
112 | /** |
||
113 | * Extract data from wbservices XML strorage to a array |
||
114 | * @param SimpleXMLElement $node |
||
115 | * @param string $environment |
||
116 | * @return array |
||
117 | */ |
||
118 | 1 | protected function extract(SimpleXMLElement $node, $environment) |
|
137 | } |
||
138 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.