ArrayAccessTrait.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. public function & offsetGet($offset)
  19. {
  20. if (isset($this->data[$offset])) {
  21. return $this->data[$offset];
  22. }
  23. $value = null;
  24. return $value;
  25. }
  26. /**
  27. * @param string $offset
  28. * @param string|mixed $value
  29. */
  30. public function offsetSet($offset, $value)
  31. {
  32. $this->data[$offset] = $value;
  33. }
  34. /**
  35. * @param string $offset
  36. *
  37. * @return bool
  38. */
  39. public function offsetExists($offset)
  40. {
  41. return isset($this->data[$offset]);
  42. }
  43. /**
  44. * @param string $offset
  45. */
  46. public function offsetUnset($offset)
  47. {
  48. unset($this->data[$offset]);
  49. }
  50. }