I do not know about C ++, but where PHP works:
For function areas:
<?php $b = 6; function testFunc($a){ echo $a.'-'.$b; } function testFunc2($a){ global $b; echo $a.'-'.$b; } testFunc(3); testFunc2(3); ?>
Output signal
3-
3-6
Internal code functions can only be accessed by variables outside functions using the global keyword. See http://php.net/manual/en/language.variables.scope.php
Regarding classes:
<?php class ExampleClass{ private $private_var = 40; public $public_var = 20; public static $static_var = 50; private function classFuncOne(){ echo $this->private_var.'-'.$this->public_var;
Output:
40-20
-
fifty
Fatal error: calling the private method ExampleClass :: classFuncOne () from the context '' in C: \ xampp \ htdocs \ scope.php on line 22
One note: PHP does not have variable initialization, although it is believed that the variables are set or not set. When a variable is set, it is assigned a value. You can use unset to remove a variable and its value. An undefined variable is equivalent to false, and if you use it with all error outputs, you will see an E_NOTICE error.
source share