From 2fddf0989929f0c0f835bccd5af859d8becd37df Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Mon, 14 Sep 2026 16:24:06 +0300 Subject: [PATCH 1/4] implement is_dir --- runtime-light/stdlib/file/file-system-functions.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/runtime-light/stdlib/file/file-system-functions.h b/runtime-light/stdlib/file/file-system-functions.h index ea10a4fa63..8741257e5f 100644 --- a/runtime-light/stdlib/file/file-system-functions.h +++ b/runtime-light/stdlib/file/file-system-functions.h @@ -237,6 +237,15 @@ inline Optional> f$file(const string& name) noexcept { return result; } +inline bool f$is_dir(const string& name) noexcept { + struct stat stat_buf {}; + // TODO: the semantics in PHP are different: PHP expects stat + if (!k2::lstat(name.c_str(), std::addressof(stat_buf)).has_value()) { + return false; + } + return S_ISDIR(stat_buf.st_mode); +} + inline bool f$is_file(const string& name) noexcept { struct stat stat_buf {}; // TODO: the semantics in PHP are different: PHP expects stat From 1a87315f3dd2e73a4bde3fcc41298285b9bba79f Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Mon, 14 Sep 2026 16:24:49 +0300 Subject: [PATCH 2/4] update file-functions.txt --- builtin-functions/kphp-light/stdlib/file-functions.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin-functions/kphp-light/stdlib/file-functions.txt b/builtin-functions/kphp-light/stdlib/file-functions.txt index a04f361f1a..4de0dff12c 100644 --- a/builtin-functions/kphp-light/stdlib/file-functions.txt +++ b/builtin-functions/kphp-light/stdlib/file-functions.txt @@ -48,6 +48,8 @@ function file_exists ($name ::: string) ::: bool; function file ($name ::: string) ::: string[] | false; +function is_dir ($name ::: string) ::: bool; + function is_file ($name ::: string) ::: bool; function fgets ($stream ::: mixed, $length ::: int = -1) ::: string | false; @@ -66,8 +68,6 @@ function filectime ($name ::: string) ::: int | false; /** @kphp-extern-func-info stub generation-required */ function filemtime ($name ::: string) ::: int | false; /** @kphp-extern-func-info stub generation-required */ -function is_dir ($name ::: string) ::: bool; -/** @kphp-extern-func-info stub generation-required */ function is_readable ($name ::: string) ::: bool; /** @kphp-extern-func-info stub generation-required */ function mkdir ($name ::: string, $mode ::: int = 0777, $recursive ::: bool = false) ::: bool; From 4ed9a444ec2357060ba7975b52c736e40c96f547 Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Mon, 14 Sep 2026 17:01:42 +0300 Subject: [PATCH 3/4] test --- tests/phpt/dl/473_file_for_k2.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/phpt/dl/473_file_for_k2.php b/tests/phpt/dl/473_file_for_k2.php index 1d40c542c2..6ada137428 100644 --- a/tests/phpt/dl/473_file_for_k2.php +++ b/tests/phpt/dl/473_file_for_k2.php @@ -8,6 +8,7 @@ var_dump (basename ('/etc/sudoers.d', '.d')); $filename = '/tmp/' . rand(1, 2e9); + var_dump (is_dir ($filename)); var_dump (is_file ($filename)); // var_dump ($filename); $file = fopen ($filename, "w"); From 2e23f58c09ee032da3add1863a2a0b9a80cbfdf6 Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Wed, 16 Sep 2026 15:25:01 +0300 Subject: [PATCH 4/4] test is_dir('/tmp') --- tests/phpt/dl/473_file_for_k2.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/phpt/dl/473_file_for_k2.php b/tests/phpt/dl/473_file_for_k2.php index 6ada137428..08414fe1f4 100644 --- a/tests/phpt/dl/473_file_for_k2.php +++ b/tests/phpt/dl/473_file_for_k2.php @@ -8,6 +8,7 @@ var_dump (basename ('/etc/sudoers.d', '.d')); $filename = '/tmp/' . rand(1, 2e9); + var_dump (is_dir ('/tmp')); var_dump (is_dir ($filename)); var_dump (is_file ($filename)); // var_dump ($filename);