<?php
class Foo
{
protected $foo;
protected $bar;
protected $baz;
}
class FooSelfHydratingProxy extends Foo
{
/** zero-argument constructor since this is just a helper class for hydration */
public function __construct()
{
}
/**
* the `Foo` typehint is not part of the interface - here only for the sake of readability/clearness
*/
public function hydrate($data, Foo $object)
{
$object->foo = $data['foo'];
$object->bar = $data['bar'];
$object->baz = $data['baz'];
}
/**
* the `Foo` typehint is not part of the interface - here only for the sake of readability/clearness
*/
public function extract(Foo $object)
{
return array('foo' => $object->foo, 'bar' => $object->bar, 'baz' => $object->baz);
}
}
$iterations = 100000;
class A {protected $a; protected $b; protected $c;}
class AHydrator extends A {
public function hydrate(A $a, array $data)
{
$a->a = $data['a'];
$a->b = $data['b'];
$a->c = $data['c'];
}
}
$data = array('a' => 1, 'b' => 2, 'c' => 3);
$a = new A();
$h = new AHydrator();
for ($i = 0; $i < $iterations; $i++) {
$h->hydrate($a, $data);
}
$iterations = 100000;
class A {protected $a; protected $b; protected $c;}
$rA = new ReflectionProperty('A', 'a');
$rB = new ReflectionProperty('A', 'b');
$rC = new ReflectionProperty('A', 'c');
$rA->setAccessible(true);
$rB->setAccessible(true);
$rC->setAccessible(true);
$data = array('a' => 1, 'b' => 2, 'c' => 3);
$a = new A();
for ($i = 0; $i < $iterations; $i++) {
$rA->setValue($a, $data['a']);
$rB->setValue($a, $data['b']);
$rC->setValue($a, $data['c']);
}
Fatal error: Cannot redeclare class A in /in/cTtZJ on line 53
Process exited with code 255.
Output for 5.1.0 - 5.1.6
Fatal error: Cannot redeclare class a in /in/cTtZJ on line 53
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/cTtZJ on line 38
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/cTtZJ on line 5
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/cTtZJ on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/cTtZJ on line 5
Process exited with code 255.