<?php
class A
{
protected $id;
protected $displanyName;
}
class B extends A implements ArrayAccess
{
public function offsetSet($offset, $value)
{
$offset = $this->_mapField($offset);
$this->$offset = $value;
}
public function offsetExists($offset)
{
$offset = $this->_mapField($offset);
return isset($this->$offset);
}
public function offsetUnset($offset)
{
$offset = $this->_mapField($offset);
throw new \Exception("Cannot remove the property $offset");
}
public function offsetGet($offset)
{
$offset = $this->_mapField($offset);
if ($this->offsetExists($offset)) {
return $this->$offset;
}
throw new \Exception("$offset property does not exists");
}
private function _mapField($keyFrom)
{
if ($keyFrom === 'id_user') {
return 'id';
} elseif ($keyFrom === 'name') {
return 'displayName';
}
return $keyFrom;
}
}
$b = new B();
var_dump($b->id);
var_dump($b->id_user);
var_dump($b->displayName);
var_dump($b->name);
Deprecated: Return type of B::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/GebeT on line 18
Deprecated: Return type of B::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/GebeT on line 30
Deprecated: Return type of B::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/GebeT on line 12
Deprecated: Return type of B::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/GebeT on line 24
Fatal error: Uncaught Error: Cannot access protected property B::$id in /in/GebeT:53
Stack trace:
#0 {main}
thrown in /in/GebeT on line 53
Process exited with code 255.
Fatal error: Uncaught Error: Cannot access protected property B::$id in /in/GebeT:53
Stack trace:
#0 {main}
thrown in /in/GebeT on line 53
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Cannot access protected property B::$id in /in/GebeT on line 53
Process exited with code 255.