php 变量作用域

以下为 PHP 中的各种变量在底层实现中是如何存储的。

变量:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$temp = 'temp';
$temp2 = $temp;
p *executor_globals.symbol_table.arData[7][email protected]4
p *executor_globals.symbol_table.arData[8][email protected]4
// value
p *executor_globals.symbol_table.arData[7][email protected]4
p *executor_globals.symbol_table.arData[8][email protected]4
$temp = 'temp';
$temp2 = &$temp;
// value
p *executor_globals.symbol_table.arData[7][email protected]4
p *executor_globals.symbol_table.arData[8][email protected]4

方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function (){
$temp = 'temp';
static $test = 'test';
}
// function name
p *executor_globals.function_table.arData[924][email protected]4
// function body
p *executor_globals.function_table.arData[924].val.value.func
// function temp variable key
p *executor_globals.function_table.arData[924].val.value.func.op_array.vars[0][email protected]4
// function temp variable value
p *executor_globals.function_table.arData[924].val.value.func.op_array.literals[0][email protected]4
// function static variable key
p *executor_globals.function_table.arData[924].val.value.func.op_array.static_variables.arData[0][email protected]2
// function static variable value
p *executor_globals.function_table.arData[924].val.value.func.op_array.static_variables.arData[0][email protected]4

常量:

1
2
3
4
5
6
7
8
// php
define('AA', 'aa');
p *executor_globals.zend_constants.arData[849][email protected]2
// value
p *executor_globals.zend_constants.arData[849][email protected]2

class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// php
class Apple{
public $a = 'avalue';
public $a2 = 'avalue';
public static $b = 'bvalue';
public static $b2 = 'bvalue';
const E = 'evalue';
const F = 'fvalue';
public function (){
  $c = 'cvalue';
  vr_dump($this->a, $c);
}
 
public static function test2(){
  $d = 'dvalue';
  vr_dump(self::$b, $d);
}
}
$obj = new Apple();
$obj->test();
Apple::test2();
// class name 类名保存在class_table的时候的 key 是不区分大小写的,但是类名字本身在 class_entry 中还是有大小写的
p *executor_globals.class_table.arData[153][email protected]5 // 小写
p *executor_globals.class_table.arData[153][email protected]5 // 保持原样
// class body
p *executor_globals.class_table.arData[153].val.value.ce
// class protetry key
p *executor_globals.class_table.arData[153].val.value.ce.properties_info.arData[0][email protected]2
// class protetry value
p *executor_globals.class_table.arData[153].val.value.ce.default_properties_table.value.str[0][email protected]6
// class static protetry value
p *executor_globals.class_table.arData[153].val.value.ce.default_static_members_table.value.str[0][email protected]6
// class constanct name
p *executor_globals.class_table.arData[153].val.value.ce.constants_table.arData[0].key
// class constanct value
p *executor_globals.class_table.arData[153].val.value.ce.constants_table.arData[0][email protected]6
// class function name
p *executor_globals.class_table.arData[153].val.value.ce.function_table.arData[0][email protected]4
// class function body
p *executor_globals.class_table.arData[153].val.value.ce.function_table.arData[0].val.value.func
// class function temp variable
p *executor_globals.class_table.arData[153].val.value.ce.function_table.arData[0].val.value.func.op_array.vars[0].val