Skip to content

Instantly share code, notes, and snippets.

@burk3
Created August 13, 2012 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burk3/3341836 to your computer and use it in GitHub Desktop.
Save burk3/3341836 to your computer and use it in GitHub Desktop.
Unfortunate behavior resulting from extending IteratorIterator
A: object(A)#1 (2) {
["extra":"A":private]=>
string(18) "not gonna see this"
["storage":"ArrayIterator":private]=>
array(5) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
}
}
extra: not gonna see this
B: object(b)#2 (0) {
}
Notice: Undefined property: b::$extra in /root/blankdir/test.php on line 12
extra:
<?php
class A extends ArrayIterator {
private $extra;
public function __construct($extra) {
$this->extra = $extra;
parent::__construct(array(1,2,3,4,5));
}
public function count() {
var_dump($this);
echo "extra: {$this->extra}\n";
return 5;
}
}
class b extends IteratorIterator {
}
$a = new A("not gonna see this");
$b = new B($a);
echo "A: ";
$a->count();
echo "\n\nB: ";
$b->count();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment