ArrayAccessTrait.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace AlibabaCloud\Client\Traits;
  3. /**
  4. * Trait ArrayAccessTrait
  5. *
  6. * @package AlibabaCloud\Client\Traits
  7. */
  8. trait ArrayAccessTrait
  9. {
  10. /**
  11. * This method returns a reference to the variable to allow for indirect
  12. * array modification (e.g., $foo['bar']['baz'] = 'qux').
  13. *
  14. * @param string $offset
  15. *
  16. * @return mixed|null
  17. */
  18. #[\ReturnTypeWillChange]
  19. public function & offsetGet($offset)
  20. {
  21. if (isset($this->data[$offset])) {
  22. return $this->data[$offset];
  23. }
  24. $value = null;
  25. return $value;
  26. }
  27. /**
  28. * @param string $offset
  29. * @param string|mixed $value
  30. */
  31. #[\ReturnTypeWillChange]
  32. public function offsetSet($offset, $value)
  33. {
  34. $this->data[$offset] = $value;
  35. }
  36. /**
  37. * @param string $offset
  38. *
  39. * @return bool
  40. */
  41. #[\ReturnTypeWillChange]
  42. public function offsetExists($offset)
  43. {
  44. return isset($this->data[$offset]);
  45. }
  46. /**
  47. * @param string $offset
  48. */
  49. #[\ReturnTypeWillChange]
  50. public function offsetUnset($offset)
  51. {
  52. unset($this->data[$offset]);
  53. }
  54. }