Language support
Supported PHP
language features
elephc compiles a growing static subset of PHP to native code. Most supported programs are
ordinary PHP, while pointer helpers like ptr()
and ptr_cast<T>() intentionally extend the syntax.
Twenty-one user-facing types are supported, including raw pointers for low-level memory work.
PHP to native assembly
Supported PHP is parsed, checked, lowered to assembly for the selected target, then assembled and linked into native output.
Native extension path
Standalone binaries are the current output. Shared/static libraries and a PHP extension bridge are on the roadmap for compiled modules.
Standalone web server
Compile a PHP file with --web to produce a prefork HTTP server binary: per-request fresh state, standard superglobals, response control, and clean signal shutdown.
Runtime dead stripping
The linker drops unreachable runtime helpers so compiled binaries include only the code the program actually uses, shrinking output without changing behavior.
Debuggable native output
--emit-asm, --source-map v2, and --debug-info embed DWARF line tables so debuggers and profilers resolve PHP source lines in the generated binary.
Static subset boundary
elephc is not trying to execute every dynamic PHP pattern by fallback. Unsupported behavior is reported at compile time where the compiler cannot prove it.
Type system
int 42, 0xFF, 0o755, 0b1010, 1_000_000 float 3.14, .5, 1e-5, 1_000.5, INF string "hello\n", 'raw' bool true, false null null array [1,2], ["k"=>"v"], heterogeneous payloads, $a + $b (union) callable function($x) { }, fn($x) => $x object new Point(3, 4) pointer ptr($x), ptr_null(), ptr_cast<int>($p) mixed mixed $x = 42 iterable iterable $x = [1, 2, 3] resource $f = fopen("data.txt", "r") enum enum Color: int { case Red = 1; } union int|string $x = 42 intersection Renderable&Cacheable $widget nullable ?int $x = null literal pseudo-types int|false, string|null relative class types self, static, parent never function fail(): never { throw ... } buffer buffer<int> $xs = buffer_new<int>(256) packed packed class Vec2 { float $x; float $y; } A variable's type is set at first assignment. Compatible types (int, float, bool, null) can be reassigned between each other. Type errors are caught at compile time with line:col error messages.
Supported constructs
Compile-time error messages
Standard library
436+ compiled PHP
built-in functions
The PHP compiler supports over 436 built-in PHP functions — from string manipulation and array operations to file I/O, images, and math. Each function is compiled directly to native instructions for the selected target, with its own documented codegen file.
Strings 71 functions
addslashes base64_decode base64_encode bin2hex chop chr crc32 explode grapheme_strrev gzcompress gzdeflate gzinflate gzuncompress hash hash_algos hash_copy hash_equals hash_final hash_hmac hash_init hash_update hex2bin html_entity_decode htmlentities htmlspecialchars implode inet_ntop inet_pton ip2long lcfirst long2ip ltrim md5 nl2br number_format ord printf rawurldecode rawurlencode rtrim sha1 sprintf sscanf str_contains str_ends_with str_ireplace str_pad str_repeat str_replace str_split str_starts_with strcasecmp strcmp stripslashes strlen strpos strrev strrpos strstr strtolower strtoupper substr substr_replace trim ucfirst ucwords urldecode urlencode vprintf vsprintf wordwrap Arrays 63 functions
array_all array_any array_chunk array_column array_combine array_diff array_diff_assoc array_diff_key array_fill array_fill_keys array_filter array_find array_flip array_intersect array_intersect_assoc array_intersect_key array_is_list array_key_exists array_key_first array_key_last array_keys array_map array_merge array_merge_recursive array_multisort array_pad array_pop array_product array_push array_rand array_reduce array_replace array_replace_recursive array_reverse array_search array_shift array_slice array_splice array_sum array_udiff array_uintersect array_unique array_unshift array_values array_walk array_walk_recursive arsort asort call_user_func call_user_func_array count in_array krsort ksort natcasesort natsort range rsort shuffle sort uasort uksort usort Math 36 functions
abs acos asin atan atan2 ceil clamp cos cosh deg2rad exp fdiv floor fmod hypot intdiv is_finite is_infinite is_nan log log10 log2 max min mt_rand pi pow rad2deg rand random_int round sin sinh sqrt tan tanh Types 23 functions
boolval ctype_alnum ctype_alpha ctype_digit ctype_space floatval get_resource_id get_resource_type gettype intval is_array is_bool is_callable is_float is_int is_iterable is_null is_numeric is_object is_resource is_scalar is_string settype Classes & Introspection 19 functions
class_alias class_attribute_args class_attribute_names class_exists class_get_attributes class_implements class_parents class_uses enum_exists function_exists get_class get_declared_classes get_declared_interfaces get_declared_traits get_parent_class interface_exists is_a is_subclass_of trait_exists SPL / Autoload 12 functions
iterator_apply iterator_count iterator_to_array spl_autoload spl_autoload_call spl_autoload_extensions spl_autoload_functions spl_autoload_register spl_autoload_unregister spl_classes spl_object_hash spl_object_id Regex 6 functions
mb_ereg_match preg_match preg_match_all preg_replace preg_replace_callback preg_split JSON 5 functions
json_decode json_encode json_last_error json_last_error_msg json_validate Date & Time 13 functions
checkdate date date_default_timezone_get date_default_timezone_set getdate gmdate gmmktime hrtime localtime microtime mktime strtotime time Images 4 functions
getimagesize getimagesizefromstring image_type_to_extension image_type_to_mime_type Filesystem 55 functions
basename chdir chgrp chmod chown clearstatcache copy dirname disk_free_space disk_total_space file_exists fileatime filectime filegroup fileinode filemtime fileowner fileperms filesize filetype fnmatch getcwd getenv glob is_dir is_executable is_file is_link is_readable is_writable is_writeable lchgrp lchown link linkinfo lstat mkdir pathinfo putenv readfile readlink realpath realpath_cache_get realpath_cache_size rename rmdir scandir stat symlink sys_get_temp_dir tempnam tmpfile touch umask unlink I/O 77 functions
closedir fclose fdatasync feof fflush fgetc fgetcsv fgets file file_get_contents file_put_contents flock fopen fpassthru fprintf fputcsv fread fscanf fseek fstat fsync ftell ftruncate fwrite gethostbyaddr gethostbyname gethostname getprotobyname getprotobynumber getservbyname getservbyport hash_file opendir readdir rewind rewinddir stream_bucket_make_writeable stream_bucket_new stream_context_create stream_context_get_default stream_context_get_options stream_context_get_params stream_context_set_default stream_context_set_option stream_context_set_params stream_copy_to_stream stream_filter_register stream_filter_remove stream_get_contents stream_get_filters stream_get_line stream_get_meta_data stream_get_transports stream_get_wrappers stream_is_local stream_isatty stream_resolve_include_path stream_select stream_set_blocking stream_set_chunk_size stream_set_read_buffer stream_set_timeout stream_set_write_buffer stream_socket_accept stream_socket_client stream_socket_enable_crypto stream_socket_get_name stream_socket_pair stream_socket_recvfrom stream_socket_sendto stream_socket_server stream_socket_shutdown stream_supports_lock stream_wrapper_register stream_wrapper_restore stream_wrapper_unregister vfprintf Streams & Sockets 6 functions
fsockopen pfsockopen stream_bucket_append stream_bucket_prepend stream_filter_append stream_filter_prepend Process 11 functions
die exec exit passthru pclose popen readline shell_exec sleep system usleep Misc 14 functions
buffer_new define defined empty header http_response_code isset php_uname phpversion print_r serialize unserialize unset var_dump Pointers 19 functions
ptr ptr_get ptr_is_null ptr_null ptr_offset ptr_read16 ptr_read32 ptr_read8 ptr_read_string ptr_set ptr_sizeof ptr_write16 ptr_write32 ptr_write8 ptr_write_string zval_free zval_pack zval_type zval_unpack Buffers 2 functions
buffer_free buffer_len Debug 3 entries
var_dump print_r var_export System 29 entries
exit die define defined time microtime sleep usleep getenv putenv php_uname phpversion exec shell_exec system passthru class_attribute_args class_attribute_names class_get_attributes json_encode json_decode json_last_error json_last_error_msg json_validate preg_match preg_match_all preg_replace preg_replace_callback preg_split Calendar 18 entries
gregoriantojd jdtogregorian juliantojd jdtojulian frenchtojd jdtofrench jewishtojd jdtojewish cal_to_jd cal_from_jd cal_days_in_month cal_info jddayofweek jdmonthname easter_days easter_date unixtojd jdtounix Constants 60 entries
INF NAN PHP_INT_MAX PHP_INT_MIN PHP_FLOAT_MAX PHP_FLOAT_MIN PHP_FLOAT_EPSILON M_PI M_E M_SQRT2 M_PI_2 M_PI_4 M_LOG2E M_LOG10E PHP_EOL PHP_OS DIRECTORY_SEPARATOR STDIN STDOUT STDERR PATHINFO_DIRNAME PATHINFO_BASENAME PATHINFO_EXTENSION PATHINFO_FILENAME PATHINFO_ALL FNM_NOESCAPE FNM_PATHNAME FNM_PERIOD FNM_CASEFOLD LOCK_SH LOCK_EX LOCK_UN LOCK_NB JSON_HEX_TAG JSON_HEX_AMP JSON_HEX_APOS JSON_HEX_QUOT JSON_FORCE_OBJECT JSON_NUMERIC_CHECK JSON_UNESCAPED_SLASHES JSON_PRETTY_PRINT JSON_UNESCAPED_UNICODE JSON_PARTIAL_OUTPUT_ON_ERROR JSON_PRESERVE_ZERO_FRACTION JSON_INVALID_UTF8_IGNORE JSON_INVALID_UTF8_SUBSTITUTE JSON_THROW_ON_ERROR JSON_OBJECT_AS_ARRAY JSON_BIGINT_AS_STRING JSON_ERROR_NONE JSON_ERROR_DEPTH JSON_ERROR_STATE_MISMATCH JSON_ERROR_CTRL_CHAR JSON_ERROR_SYNTAX JSON_ERROR_UTF8 JSON_ERROR_RECURSION JSON_ERROR_INF_OR_NAN JSON_ERROR_UNSUPPORTED_TYPE JSON_ERROR_INVALID_PROPERTY_NAME JSON_ERROR_UTF16