Example #2 has a mistake.
This one works fine:
<?php
/* example by Erik Jenssen aka erix */
$filename = "foobar.rar";
$filepath = "/home/foo/bar/";
$rar_file = rar_open($filepath.$filename);
$list = rar_list($rar_file);
foreach($list as $file) {
$entry = rar_entry_get($rar_file, $file->getName());
$entry->extract("."); // extract to the current dir
}
rar_close($rar_file);
?>