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.
Eighteen 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.
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 nullable ?int $x = null 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
290+ compiled PHP
built-in functions
The PHP compiler supports over 290 built-in PHP functions — from string manipulation and array operations to file I/O and math. Each function is compiled directly to native instructions for the selected target, with its own documented codegen file.
Strings 57 functions
strlen intval number_format substr strpos strrpos strstr str_replace str_ireplace substr_replace strtolower strtoupper ucfirst lcfirst ucwords trim ltrim rtrim str_repeat str_pad strrev str_split strcmp strcasecmp str_contains str_starts_with str_ends_with ord chr explode implode addslashes stripslashes nl2br wordwrap bin2hex hex2bin sprintf printf sscanf md5 sha1 hash htmlspecialchars htmlentities html_entity_decode urlencode urldecode rawurlencode rawurldecode base64_encode base64_decode ctype_alpha ctype_digit ctype_alnum ctype_space Arrays 51 functions
count array_push array_pop in_array array_keys array_values sort rsort isset array_key_exists array_search array_merge array_slice array_splice array_combine array_flip array_reverse array_unique array_sum array_product array_chunk array_column array_pad array_fill array_fill_keys array_diff array_intersect array_diff_key array_intersect_key array_unshift array_shift asort arsort ksort krsort natsort natcasesort shuffle array_rand range array_map array_filter array_reduce array_walk usort uksort uasort call_user_func call_user_func_array function_exists Math 32 functions
abs acos asin atan atan2 ceil cos cosh deg2rad exp fdiv floor fmod hypot intdiv log log2 log10 max min mt_rand pi pow rad2deg rand random_int round sin sinh sqrt tan tanh Types & Introspection 23 functions
gettype settype empty unset is_int is_float is_string is_bool is_callable is_null is_numeric is_iterable is_nan is_finite is_infinite boolval floatval class_exists interface_exists trait_exists enum_exists class_alias get_class get_parent_class get_declared_classes get_declared_interfaces get_declared_traits is_a is_subclass_of SPL / Autoload 8 functions
spl_autoload_register spl_autoload_unregister spl_autoload_functions spl_autoload_extensions spl_autoload_call spl_autoload spl_classes spl_object_id spl_object_hash I/O & Filesystem 65 functions
fopen fclose fread fwrite fgets feof readline fseek ftell rewind file_get_contents file_put_contents file fgetcsv fputcsv fgetc readfile fpassthru flock tmpfile file_exists is_file is_dir is_readable is_writable is_executable is_link is_writeable filesize filemtime fileatime filectime fileperms fileowner filegroup fileinode filetype stat lstat fstat clearstatcache copy rename unlink mkdir rmdir scandir glob getcwd chdir tempnam sys_get_temp_dir basename dirname pathinfo realpath fnmatch touch chmod chown chgrp umask ftruncate fflush fsync fdatasync symlink link readlink linkinfo Pointers & Buffers 19 functions
buffer_free buffer_len buffer_new<T> ptr ptr_cast<T> ptr_get ptr_is_null ptr_null ptr_offset ptr_read8 ptr_read16 ptr_read32 ptr_read_string ptr_set ptr_sizeof ptr_write8 ptr_write16 ptr_write32 ptr_write_string Debug 2 entries
var_dump print_r System 31 entries
exit die define time microtime sleep usleep getenv putenv php_uname phpversion exec shell_exec system passthru class_attribute_args class_attribute_names class_get_attributes date mktime strtotime 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 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