Last active
August 29, 2015 14:23
-
-
Save kurt-krueckeberg/4ecf647ffebc18ed6fc7 to your computer and use it in GitHub Desktop.
Errors when using SplFileObject in a Hack class
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
<?hh | |
function test_splfile(string $file_name) : void | |
{ | |
$file1 = new SplFileObject($file_name); | |
// These loops work fine | |
foreach ($file1 as $line_number => $text) { /* hhvm: Could not find method key in an object of | |
type SplFileObject Typing[4053]) */ | |
echo $text . "\n" . $line_number; | |
} | |
$file1->rewind(); | |
while ($file1->valid()) { | |
$key = $file1->key(); | |
$value = $file1->current(); | |
$file1->next(); | |
} | |
} | |
class test { | |
protected SplFileObject $file2; // It is incompatible with an object of type SplFileObject | |
public function __construct($file_name) | |
{ | |
$this->file2 = new \SplFileObject($file_name); | |
} | |
public function test_bug() : void | |
{ | |
// Invalid foreach (Typing[4110]) | |
// This is an object of type KeyedTraversable because this is used in a foreach statement | |
foreach ($this->file2 as $line_number => $text) { | |
echo $text . "\n" . $line_number; | |
} | |
$this->file2->rewind(); | |
while ($this->file2->valid()) { | |
$key = $this->file2->key(); // Could not find method key in an object of type SplFileObject (Typing[4053]) | |
// /tmp/hh_server/hhi_3666eaf1/stdlib/builtins_spl.hhi:97:7,19: Declaration of SplFileObject is here | |
$value = $this->file2->current(); | |
$this->file2->next(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment