Created
August 13, 2012 15:25
-
-
Save burk3/3341836 to your computer and use it in GitHub Desktop.
Unfortunate behavior resulting from extending IteratorIterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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