- Output for 5.5.24 - 5.5.31, 5.6.8 - 5.6.17, 7.0.0 - 7.0.2
- Parse error: syntax error, unexpected ';', expecting function (T_FUNCTION) in /in/FI7GS on line 5
Process exited with code 255.
<?php
class A
{
protected $id = 'id';;
protected $displayName = 'name';
}
class B implements ArrayAccess
{
public function offsetSet($offset, $value)
{
$offset = $this->_mapField($offset);
$this->$offset = $value;
}
public function offsetExists($offset)
{
$offset = $this->_mapField($offset);
return property_exists($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']);