Skip to content

Instantly share code, notes, and snippets.

@tvlooy tvlooy/ffi_pledge.md
Last active Jan 21, 2019

Embed
What would you like to do?
PHP FFI obsoletes pecl/pledge

PHP FFI obsoletes pecl/pledge

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.