Arquivos
hhvm/hphp/test/slow/array_access/436.php
T
Paul Tarjan c2ec1c97c9 sortof format slow tests
A poor man's formatter since I didn't like any of the other ones I found. The original C++ source sometimes put newlines and sometimes not.

Codemods:

    codemod '([;{}])([^\n])' '\1\n\2'
    codemod -m '\s*<\?php\s+' '<?php\n\n'
    codemod '\t' '  '

I hand-fixed all the failing tests
2013-05-30 17:32:57 -07:00

102 linhas
3.1 KiB
PHP

<?php
function offsetGet($index) {
echo ("GET0: $index\n");
}
class ArrayAccessImpl implements ArrayAccess {
public $data = array();
public function offsetUnset($index) {
echo "UNSET: $index\n";
}
public function offsetSet($index, $value) {
echo ("SET: $index\n");
if(isset($data[$index])) {
unset($data[$index]);
}
$u = &$this->data[$index];
if(is_array($value)) {
$u = new ArrayAccessImpl();
foreach($value as $idx=>$e) $u[$idx]=$e;
}
else $u=$value;
}
public function offsetGet($index) {
echo ("GET: $index\n");
if(!isset($this->data[$index])) $this->data[$index]=new ArrayAccessImpl();
return $this->data[$index];
}
public function offsetExists($index) {
echo ("EXISTS: $index\n");
if(isset($this->data[$index])) {
if($this->data[$index] instanceof ArrayAccessImpl) {
if(count($this->data[$index]->data)>0) return true;
else return false;
}
else return true;
}
else return false;
}
}
class ArrayAccessImpl2 extends ArrayAccessImpl {
public function offsetUnset($index) {
echo "UNSET2: $index\n";
}
public function offsetSet($index, $value) {
echo ("SET2: $index\n");
if(isset($data[$index])) {
unset($data[$index]);
}
$u = &$this->data[$index];
if(is_array($value)) {
$u = new ArrayAccessImpl();
foreach($value as $idx=>$e) $u[$idx]=$e;
}
else $u=$value;
}
public function offsetGet($index) {
echo ("GET2: $index\n");
if(!isset($this->data[$index])) $this->data[$index]=new ArrayAccessImpl();
return $this->data[$index];
}
public function offsetExists($index) {
echo ("EXISTS2: $index\n");
if(isset($this->data[$index])) {
if($this->data[$index] instanceof ArrayAccessImpl) {
if(count($this->data[$index]->data)>0) return true;
else return false;
}
else return true;
}
else return false;
}
}
offsetGet('foo');
$data = new ArrayAccessImpl();
$data['string']="Just a simple string";
$data['number']=33;
$data['array']['another_string']="Alpha";
$data['array']['some_object']=new stdClass();
$data['array']['another_array']['x']['y']="Beta";
$data['blank_array']=array();
print_r(isset($data['array']));
print_r($data['array']['non_existent']);
print_r(isset($data['array']['non_existent']));
print_r($data['blank_array']);
print_r(isset($data['blank_array']));
unset($data['blank_array']);
print_r($data);
$data2 = new ArrayAccessImpl2();
$data2['string']="Just a simple string";
$data2['number']=33;
$data2['array']['another_string']="Alpha";
$data2['array']['some_object']=new stdClass();
$data2['array']['another_array']['x']['y']="Beta";
$data2['blank_array']=array();
print_r(isset($data2['array']));
print_r($data2['array']['non_existent']);
print_r(isset($data2['array']['non_existent']));
print_r($data2['blank_array']);
print_r(isset($data2['blank_array']));
unset($data2['blank_array']);
print_r($data2);