Home  >  Article  >  Backend Development  >  Introduction to the usage of php variable scope (code)

Introduction to the usage of php variable scope (code)

不言
不言forward
2018-10-17 15:58:592098browse

This article brings you an introduction to the usage of PHP variable scope (code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

The following is how various variables in PHP are stored in the underlying implementation.

Variables:

$temp = 'temp';
$temp2 = $temp;

// key
p *executor_globals.symbol_table.arData[7].key.val@4
p *executor_globals.symbol_table.arData[8].key.val@4

// value
p *executor_globals.symbol_table.arData[7].val.value.zv.value.str.val@4
p *executor_globals.symbol_table.arData[8].val.value.zv.value.str.val@4


$temp = 'temp';
$temp2 = &$temp;

// value
p *executor_globals.symbol_table.arData[7].val.value.zv.value.ref.val.value.str.val@4
p *executor_globals.symbol_table.arData[8].val.value.zv.value.ref.val.value.str.val@4

Methods:

function test(){
  $temp = 'temp';
  static $test = 'test';
}

// function name
p *executor_globals.function_table.arData[924].key.val@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].val@4

// function temp variable value
p *executor_globals.function_table.arData[924].val.value.func.op_array.literals[0].value.str.val@4

// function static variable key
p *executor_globals.function_table.arData[924].val.value.func.op_array.static_variables.arData[0].key.val@2

// function static variable value
p *executor_globals.function_table.arData[924].val.value.func.op_array.static_variables.arData[0].val.value.ref.val.value.str.val@4

Constants:

// php
define('AA', 'aa');

// key
p *executor_globals.zend_constants.arData[849].key.val@2

// value
p *executor_globals.zend_constants.arData[849].val.value.zv.value.str.val@2

class:

// 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 test(){
    $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].key.val@5 // 小写
p *executor_globals.class_table.arData[153].val.value.ce.name.val@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].key.val@2

// class protetry value
p *executor_globals.class_table.arData[153].val.value.ce.default_properties_table.value.str[0].val@6

// class static protetry value
p *executor_globals.class_table.arData[153].val.value.ce.default_static_members_table.value.str[0].val@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].val.value.zv.value.str.val@6

// class function name
p *executor_globals.class_table.arData[153].val.value.ce.function_table.arData[0].key.val@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

The above is the detailed content of Introduction to the usage of php variable scope (code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete