Example with pecl/pledge:
$ cat test_pecl.php
<?php
var_dump(count(scandir('/etc')));
unveil(__DIR__, 'r');
scandir('/etc');
$ php -dextension=pledge test_pecl.php
int(77)
Warning: scandir(/etc): failed to open dir: No such file or directory in /home/tvl/test_pecl.php on line 5
Warning: scandir(): (errno 2): No such file or directory in /home/tvl/test_pecl.php on line 5
Same example with (core extension) FFI:
$ cat test_ffi.php
<?php
$libc = FFI::cdef('
int unveil(const char *path, const char *permissions);
', 'libc.so.92.5');
var_dump(count(scandir('/etc')));
$libc->unveil(__DIR__, 'r');
scandir('/etc');
$ php -dextension=ffi test_ffi.php
int(77)
Warning: scandir(/etc): failed to open dir: No such file or directory in /home/tvl/test_ffi.php on line 9
Warning: scandir(): (errno 2): No such file or directory in /home/tvl/test_ffi.php on line 9