diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -419,6 +419,7 @@ 'phutil_console_prompt' => 'console/format.php', 'phutil_console_require_tty' => 'console/format.php', 'phutil_console_wrap' => 'console/format.php', + 'phutil_count' => 'internationalization/pht.php', 'phutil_date_format' => 'utils/viewutils.php', 'phutil_deprecated' => 'moduleutils/moduleutils.php', 'phutil_error_listener_example' => 'error/phlog.php', diff --git a/src/internationalization/pht.php b/src/internationalization/pht.php --- a/src/internationalization/pht.php +++ b/src/internationalization/pht.php @@ -16,3 +16,18 @@ $translator = PhutilTranslator::getInstance(); return call_user_func_array(array($translator, 'translate'), $args); } + +/** + * Count all elements in an array, or something in an object. + * + * @param array|Countable A countable object. + * @return PhutilNumber Returns the number of elements in the input + * parameter. + */ +function phutil_count($countable) { + if (!(is_array($countable) || $countable instanceof Countable)) { + throw new InvalidArgumentException(pht('Argument should be countable.')); + } + + return new PhutilNumber(count($countable)); +}