Bitrix-D7  20.5.0
arrayaccesswithreferences.php
См. документацию.
1 <?php
2 
4 
6 
8 {
9  /** @var array */
10  protected $sessionData = [];
11  /** @var array */
12  protected $nullPointers = [];
13  /** @var bool */
14  protected $strictMode = false;
15 
16  public function has($name)
17  {
18  $this->processLazyStart();
19 
20  return
21  isset($this->sessionData[$name]) ||
22  (empty($this->nullPointers[$name]) && $this->sessionData && array_key_exists($name, $this->sessionData))
23  ;
24  }
25 
26  public function &get($name)
27  {
28  $this->processLazyStart();
29 
30  if (!isset($this->sessionData[$name]) && !array_key_exists($name, $this->sessionData))
31  {
32  if ($this->strictMode)
33  {
34  $trace = Helper::getBackTrace(1, DEBUG_BACKTRACE_IGNORE_ARGS)[0];
35  trigger_error("Notice: Undefined index: {$name} in {$trace['function']} called from {$trace['file']} on line {$trace['line']}.\n", E_USER_NOTICE);
36  }
37  $this->nullPointers[$name] = true;
38  }
39 
40  return $this->sessionData[$name];
41  }
42 
43  public function set($name, $value)
44  {
45  $this->processLazyStart();
46 
47  $this->sessionData[$name] = $value;
48  unset($this->nullPointers[$name]);
49  }
50 
51  public function remove($name)
52  {
53  $this->processLazyStart();
54 
55  unset($this->sessionData[$name], $this->nullPointers[$name]);
56  }
57 
58  public function delete($name)
59  {
60  $this->remove($name);
61  }
62 
63  public function offsetExists($offset)
64  {
65  $this->processLazyStart();
66 
67  return isset($this->sessionData[$offset]);
68  }
69 
70  public function &offsetGet($offset)
71  {
72  return $this->get($offset);
73  }
74 
75  public function offsetSet($offset, $value)
76  {
77  if ($offset === null)
78  {
79  $this->processLazyStart();
80 
81  $this->sessionData[] = $value;
82  }
83  else
84  {
85  $this->set($offset, $value);
86  }
87  }
88 
89  public function offsetUnset($offset)
90  {
91  $this->remove($offset);
92  }
93 
94  public function refineReferencesBeforeSave(): void
95  {
96  foreach ($this->nullPointers as $key => $exists)
97  {
98  if ($exists === true && $this->sessionData[$key] === null)
99  {
100  unset($this->sessionData[$key]);
101  }
102  }
103 
104  $this->nullPointers = [];
105  }
106 
107  protected function processLazyStart()
108  {}
109 }
static getBackTrace($limit=0, $options=null, $skip=1)
Returns array backtrace.