@ 2012-08-14T16:33:19Z <?php
class Collection {}
class Link {}
class Node {
private $label = '_';
private $links;
private $attrs;
public function __construct($label = '_')
{
$this -> setLabel($label);
}
public function getLabel()
{
return $this -> label;
}
public function setLabel($label)
{
if (!is_scalar($label)) {
throw new ErrorException("Error Processing Request", 1);
}
$this -> label = $label;
return $this -> getLabel();
}
public function __get($name)
{
if (isset($this -> links -> $name)) {
return $this -> links -> $name;
} elseif (isset($this -> attrs -> $name)) {
return $this -> attrs -> $name;
} else {
throw new ErrorException("Error Processing Request", 1);
}
}
public function __set($name, $value)
{
if ($name == '_' && !($value instanceof Node || $value instanceof Link || $value instanceof Collection)) {
throw new ErrorException("Error Processing Request", 1);
}
$name_type = (
(1 * (isset($this -> links -> $name) && count($this -> links -> $name) == 1)) |
(2 * (isset($this -> links -> $name) && count($this -> links -> $name) <> 1)) |
(3 * isset($this -> attrs -> $name)) |
(13 * !(isset($this -> attrs -> $name) || isset($this -> links -> $name)))
);
$value_type = (
(5 * ($value instanceof Collection)) |
(7 * ($value instanceof Node)) |
(17 * ($value instanceof Link)) |
(11 * !($value instanceof Node || $value instanceof Link || $value instanceof Collection))
);
switch ($name_type * $value_type) {
case 5:
case 10: {
foreach ($value as $node) {
$this -> links -> {$name} -> attach($node);
}
break;
}
case 7:
case 14: {
$this -> links -> {$name} -> attach($value);
break;
}
case 11:
case 22: {
trigger_error('Converting ' . $name . ' from ' .
((count($this -> links -> $name) <> 1) ? 'Collection' : 'Node') .
' to property', E_USER_WARNING);
unset($this -> links -> $name);
$this -> attrs -> $name = $value;
break;
}
case 15: {
trigger_error('Converting ' . $name . ' from property to Collection', E_USER_WARNING);
unset($this -> attrs -> $name);
$this -> links -> $name = $value;
break;
}
case 21: {
trigger_error('Converting ' . $name . ' from property to Node', E_USER_WARNING);
unset($this -> attrs -> $name);
$this -> links -> $name = new Collection;
$this -> links -> {$name} -> attach($value);
break;
}
case 33:
case 143: {
$this -> attrs -> $name = $value;
break;
}
case 65: {
$this -> links -> $name = $value;
break;
}
case 91: {
$this -> links -> $name = new Collection;
$this -> links -> {$name} -> attach($value);
break;
}
case 17:
case 34: {
$this -> links -> {$name} -> attach($value -> getTail());
$this -> links -> {$name} -> attach($value -> getHead());
break;
}
case 51: {
trigger_error('Converting ' . $name . ' from property to Collection', E_USER_WARNING);
unset($this -> attrs -> $name);
$this -> links -> $name = new Collection;
$this -> links -> {$name} -> attach($value -> getTail());
$this -> links -> {$name} -> attach($value -> getHead());
break;
}
case 221: {
$this -> links -> $name = new Collection;
$this -> links -> {$name} -> attach($value -> getTail());
$this -> links -> {$name} -> attach($value -> getHead());
break;
}
default: {
throw new ErrorException("Error Processing Request", 1);
// no break
}
}
}
public function __isset($name)
{
return (isset($this -> links -> $name) || isset($this -> attrs -> $name));
}
public function __unset($name)
{
unset($this -> links -> $name, $this -> attrs -> $name);
}
public function serialize()
{
return serialize(array(
'label' => $this -> getLabel(),
'links' => $this -> links,
'attrs' => $this -> attrs
));
}
public function unserialize($serialized)
{
$unserialized = unserialize($serialized);
$this -> setLabel($unserialized['label']);
$this -> links = $unserialized['links'];
$this -> attrs = $unserialized['attrs'];
}
}
$node = new Node;
$node->self = $node;
echo serialize($node);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Fatal error: Uncaught Error: Attempt to assign property "self" on null in /in/vMA3a:104
Stack trace:
#0 /in/vMA3a(161): Node->__set('self', Object(Node))
#1 {main}
thrown in /in/vMA3a on line 104
Process exited with code 255 . Output for 7.0.0 - 7.0.20 , 7.1.0 - 7.1.25 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 Warning: Creating default object from empty value in /in/vMA3a on line 104
Fatal error: Uncaught Error: Call to undefined method Collection::attach() in /in/vMA3a:105
Stack trace:
#0 /in/vMA3a(161): Node->__set('self', Object(Node))
#1 {main}
thrown in /in/vMA3a on line 105
Process exited with code 255 . Output for 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.28 Warning: Creating default object from empty value in /in/vMA3a on line 104
Fatal error: Call to undefined method Collection::attach() in /in/vMA3a on line 105
Process exited with code 255 . Output for 5.3.0 - 5.3.29 Strict Standards: Creating default object from empty value in /in/vMA3a on line 104
Fatal error: Call to undefined method Collection::attach() in /in/vMA3a on line 105
Process exited with code 255 . preferences:dark mode live preview
233.76 ms | 401 KiB | 317 Q