PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/slow/ext_array/count-opts.php

https://github.com/xstudio/hhvm
PHP | 46 lines | 38 code | 8 blank | 0 comment | 0 complexity | b4cd0057c4af7260b7b77a51aaf832b6 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, BSD-3-Clause, LGPL-2.0, LGPL-2.1
  1. <?php
  2. class Counted implements Countable {
  3. public function count() { return 5; }
  4. }
  5. class NotCounted {
  6. public function count() { return 4; }
  7. }
  8. class BadCounted implements Countable {
  9. public function count() { throw new Exception("y u do dis"); }
  10. }
  11. function res() { return count(STDIN); }
  12. function nvtw() { return count($GLOBALS); }
  13. function staticArr() { return count(array(3,2,1,0)); }
  14. function packed() { return count(array(3,2,1,new stdClass)); }
  15. function vec() { return count(HH\Vector{5,7,8,3}); }
  16. function counted_obj() { return count(new Counted); }
  17. function not_counted_obj() { return count(new NotCounted); }
  18. function bad_counted_obj() { return count(new BadCounted); }
  19. function append($arr) {
  20. var_dump(count($arr));
  21. $new_arr = $arr;
  22. $new_arr[] = 1;
  23. var_dump(count($new_arr));
  24. }
  25. append(array(3,2));
  26. append(HH\Vector{3,2});
  27. var_dump(res());
  28. var_dump(vec());
  29. var_dump(nvtw() > 0);
  30. var_dump(packed());
  31. var_dump(staticArr());
  32. var_dump(counted_obj());
  33. var_dump(not_counted_obj());
  34. try {
  35. var_dump(bad_counted_obj());
  36. } catch (Exception $e) {
  37. var_dump($e->getMessage());
  38. }