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 library outputs
Build standalone executables, shared libraries, or static libraries with generated C headers. A macOS host can also cross-compile libraries for iOS devices and the ARM64 Simulator.
Standalone web server
Compile a PHP file with --web to produce a native HTTP server with worker, persistent pool, or per-request isolation, plus standard superglobals, sessions, response control, and clean 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.
Managed native dependencies
elephc native declares, locks, and builds curated C packages, including PCRE2, zlib, OpenSSL, nghttp2, libssh2, curl, and libxml2, into verified target-specific static artifacts. Locked builds are reproducible offline, with no production fallback to system libraries.
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.
PHP-level profiling
elephc monitor profiles local programs and running services with function, allocation, query, network, call-graph, route, and distributed-trace context.
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. --strict-php rejects every elephc extension, accepting only PHP-compatible constructs.
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 scalar types can be reassigned, while an untyped local may rebind to a new type with a warning.
Use --strict-locals to turn incompatible local retyping back into a compile-time error. Typed locals, parameters, and properties remain strict.
Supported constructs
Compile-time error messages
Standard library
978 compiled PHP
built-in functions
The PHP compiler supports 978 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 99 functions
addslashes base64_decode base64_encode bin2hex chop chr chunk_split count_chars 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 iconv iconv_get_encoding iconv_mime_decode iconv_mime_decode_headers iconv_mime_encode iconv_set_encoding iconv_strlen iconv_strpos iconv_strrpos iconv_substr implode inet_ntop inet_pton ip2long join lcfirst long2ip ltrim mb_strlen md5 nl2br number_format openssl_cipher_iv_length openssl_decrypt openssl_encrypt openssl_get_cipher_methods ord parse_url printf quoted_printable_encode quotemeta rawurldecode rawurlencode rtrim sha1 sprintf sscanf str_contains str_ends_with str_ireplace str_pad str_repeat str_replace str_split str_starts_with str_word_count strcasecmp strcmp stripos stripslashes strlen strncasecmp strncmp strpos strrev strripos strrpos strstr strtolower strtoupper strtr substr substr_count substr_replace trim ucfirst ucwords urldecode urlencode vprintf vsprintf wordwrap Arrays 70 functions
array_all array_any array_chunk array_column array_combine array_count_values 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 current end in_array key krsort ksort natcasesort natsort next prev range reset rsort shuffle sort uasort uksort usort Math 57 functions
abs acos asin atan atan2 base_convert bcadd bcceil bccomp bcdiv bcdivmod bcfloor bcmod bcmul bcpow bcpowmod bcround bcscale bcsqrt bcsub bindec ceil clamp cos cosh decbin dechex decoct deg2rad exp fdiv floor fmod hexdec hypot intdiv is_finite is_infinite is_nan log log10 log2 max min mt_rand octdec pi pow rad2deg rand random_int round sin sinh sqrt tan tanh Types 29 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_double is_float is_int is_integer is_iterable is_long is_null is_numeric is_object is_real is_resource is_scalar is_string settype strval var_export Classes & Introspection 25 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_called_class get_class get_class_methods get_class_vars get_declared_classes get_declared_interfaces get_declared_traits get_object_vars get_parent_class interface_exists is_a is_subclass_of method_exists property_exists 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 70 functions
cal_days_in_month cal_from_jd cal_info cal_to_jd checkdate date date_add date_create date_create_from_format date_create_immutable date_create_immutable_from_format date_date_set date_default_timezone_get date_default_timezone_set date_diff date_format date_get_last_errors date_interval_create_from_date_string date_interval_format date_isodate_set date_modify date_offset_get date_parse date_parse_from_format date_sub date_sun_info date_sunrise date_sunset date_time_set date_timestamp_get date_timestamp_set date_timezone_get date_timezone_set easter_date easter_days frenchtojd getdate gettimeofday gmdate gmmktime gmstrftime gregoriantojd hrtime idate jddayofweek jdmonthname jdtofrench jdtogregorian jdtojewish jdtojulian jdtounix jewishtojd juliantojd localtime microtime mktime strftime strptime strtotime time timezone_abbreviations_list timezone_identifiers_list timezone_location_get timezone_name_from_abbr timezone_name_get timezone_offset_get timezone_open timezone_transitions_get timezone_version_get unixtojd Images 142 functions
cairo_arc cairo_arc_negative cairo_close_path cairo_create cairo_curve_to cairo_fill cairo_fill_preserve cairo_get_current_point cairo_identity_matrix cairo_image_surface_create cairo_image_surface_create_from_png cairo_image_surface_get_height cairo_image_surface_get_width cairo_line_to cairo_matrix_init_identity cairo_matrix_init_rotate cairo_matrix_init_scale cairo_matrix_init_translate cairo_matrix_multiply cairo_matrix_transform_point cairo_move_to cairo_new_path cairo_new_sub_path cairo_paint cairo_pattern_add_color_stop_rgb cairo_pattern_add_color_stop_rgba cairo_pattern_create_linear cairo_pattern_create_radial cairo_pattern_create_rgb cairo_pattern_create_rgba cairo_rectangle cairo_restore cairo_rotate cairo_save cairo_scale cairo_set_fill_rule cairo_set_line_cap cairo_set_line_join cairo_set_line_width cairo_set_matrix cairo_set_source cairo_set_source_rgb cairo_set_source_rgba cairo_stroke cairo_stroke_preserve cairo_surface_write_to_png cairo_transform cairo_translate exif_imagetype exif_read_data exif_tagname exif_thumbnail gd_info getimagesize getimagesizefromstring image_type_to_extension image_type_to_mime_type imageaffine imageaffinematrixconcat imagealphablending imageantialias imagearc imagebmp imagechar imagecharup imagecolorallocate imagecolorallocatealpha imagecolorat imagecolorclosest imagecolorclosestalpha imagecolorclosesthwb imagecolordeallocate imagecolorexact imagecolorexactalpha imagecolormatch imagecolorresolve imagecolorresolvealpha imagecolorset imagecolorsforindex imagecolorstotal imagecolortransparent imageconvolution imagecopy imagecopymerge imagecopymergegray imagecopyresampled imagecopyresized imagecreate imagecreatefrombmp imagecreatefromgif imagecreatefromjpeg imagecreatefrompng imagecreatefromstring imagecreatefromtga imagecreatefromwebp imagecreatetruecolor imagecrop imagecropauto imagedashedline imagedestroy imageellipse imagefill imagefilledarc imagefilledellipse imagefilledpolygon imagefilledrectangle imagefilltoborder imagefilter imageflip imagefontheight imagefontwidth imagegammacorrect imagegetinterpolation imagegif imageinterlace imageistruecolor imagejpeg imagelayereffect imageline imageopenpolygon imagepalettecopy imagepalettetotruecolor imagepng imagepolygon imagerectangle imageresolution imagerotate imagesavealpha imagescale imagesetinterpolation imagesetpixel imagesetthickness imagestring imagestringup imagesx imagesy imagetruecolortopalette imagetypes imagewebp iptcembed iptcparse read_exif_data 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 90 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 ob_clean ob_end_clean ob_end_flush ob_flush ob_get_clean ob_get_contents ob_get_flush ob_get_length ob_get_level ob_get_status ob_implicit_flush ob_list_handlers ob_start 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 Database (PDO / mysqli) 85 functions
mysqli_affected_rows mysqli_autocommit mysqli_begin_transaction mysqli_character_set_name mysqli_close mysqli_commit mysqli_connect mysqli_connect_errno mysqli_connect_error mysqli_data_seek mysqli_errno mysqli_error mysqli_error_list mysqli_escape_string mysqli_execute mysqli_execute_query mysqli_fetch_all mysqli_fetch_array mysqli_fetch_assoc mysqli_fetch_column mysqli_fetch_field mysqli_fetch_field_direct mysqli_fetch_fields mysqli_fetch_lengths mysqli_fetch_object mysqli_fetch_row mysqli_field_count mysqli_field_seek mysqli_field_tell mysqli_free_result mysqli_get_charset mysqli_get_client_info mysqli_get_client_version mysqli_get_host_info mysqli_get_proto_info mysqli_get_server_info mysqli_get_server_version mysqli_info mysqli_init mysqli_insert_id mysqli_more_results mysqli_multi_query mysqli_next_result mysqli_num_fields mysqli_num_rows mysqli_options mysqli_ping mysqli_prepare mysqli_query mysqli_real_connect mysqli_real_escape_string mysqli_real_query mysqli_release_savepoint mysqli_report mysqli_rollback mysqli_savepoint mysqli_select_db mysqli_set_charset mysqli_set_opt mysqli_sqlstate mysqli_stat mysqli_stmt_affected_rows mysqli_stmt_bind_param mysqli_stmt_close mysqli_stmt_errno mysqli_stmt_error mysqli_stmt_error_list mysqli_stmt_execute mysqli_stmt_field_count mysqli_stmt_free_result mysqli_stmt_get_result mysqli_stmt_init mysqli_stmt_insert_id mysqli_stmt_num_rows mysqli_stmt_param_count mysqli_stmt_prepare mysqli_stmt_reset mysqli_stmt_sqlstate mysqli_stmt_store_result mysqli_store_result mysqli_thread_id mysqli_thread_safe mysqli_use_result mysqli_warning_count pdo_drivers Streams & Sockets 6 functions
fsockopen pfsockopen stream_bucket_append stream_bucket_prepend stream_filter_append stream_filter_prepend Network / cURL 34 functions
curl_close curl_copy_handle curl_errno curl_error curl_escape curl_exec curl_getinfo curl_init curl_multi_add_handle curl_multi_close curl_multi_errno curl_multi_exec curl_multi_get_handles curl_multi_getcontent curl_multi_info_read curl_multi_init curl_multi_remove_handle curl_multi_select curl_multi_setopt curl_multi_strerror curl_pause curl_reset curl_setopt curl_setopt_array curl_share_close curl_share_errno curl_share_init curl_share_init_persistent curl_share_setopt curl_share_strerror curl_strerror curl_unescape curl_upkeep curl_version Web & Sessions 30 functions
error_log ini_get ini_get_all ini_set session_abort session_cache_expire session_cache_limiter session_commit session_create_id session_decode session_destroy session_encode session_gc session_get_cookie_params session_id session_module_name session_name session_regenerate_id session_register_shutdown session_reset session_save_path session_set_cookie_params session_set_save_handler session_start session_status session_unset session_write_close setcookie setrawcookie trigger_error XML 64 functions
xml_error_string xml_get_current_byte_index xml_get_current_column_number xml_get_current_line_number xml_get_error_code xml_parse xml_parse_into_struct xml_parser_create xml_parser_create_ns xml_parser_free xml_parser_get_option xml_parser_set_option xml_set_character_data_handler xml_set_default_handler xml_set_element_handler xml_set_end_namespace_decl_handler xml_set_external_entity_ref_handler xml_set_notation_decl_handler xml_set_object xml_set_processing_instruction_handler xml_set_start_namespace_decl_handler xml_set_unparsed_entity_decl_handler xmlwriter_end_attribute xmlwriter_end_cdata xmlwriter_end_comment xmlwriter_end_document xmlwriter_end_dtd xmlwriter_end_dtd_attlist xmlwriter_end_dtd_element xmlwriter_end_dtd_entity xmlwriter_end_element xmlwriter_end_pi xmlwriter_flush xmlwriter_full_end_element xmlwriter_open_memory xmlwriter_open_uri xmlwriter_output_memory xmlwriter_set_indent xmlwriter_set_indent_string xmlwriter_start_attribute xmlwriter_start_attribute_ns xmlwriter_start_cdata xmlwriter_start_comment xmlwriter_start_document xmlwriter_start_dtd xmlwriter_start_dtd_attlist xmlwriter_start_dtd_element xmlwriter_start_dtd_entity xmlwriter_start_element xmlwriter_start_element_ns xmlwriter_start_pi xmlwriter_text xmlwriter_write_attribute xmlwriter_write_attribute_ns xmlwriter_write_cdata xmlwriter_write_comment xmlwriter_write_dtd xmlwriter_write_dtd_attlist xmlwriter_write_dtd_element xmlwriter_write_dtd_entity xmlwriter_write_element xmlwriter_write_element_ns xmlwriter_write_pi xmlwriter_write_raw Process 11 functions
die exec exit passthru pclose popen readline shell_exec sleep system usleep Misc 62 functions
constant define defined empty extension_loaded get_loaded_extensions header http_response_code ini_restore isset opcache_compile_file opcache_get_configuration opcache_get_status opcache_invalidate opcache_is_script_cached opcache_is_script_cached_in_file_cache opcache_jit_blacklist opcache_reset pcntl_alarm pcntl_async_signals pcntl_daemon pcntl_errno pcntl_exec pcntl_fork pcntl_get_last_error pcntl_getcpu pcntl_getcpuaffinity pcntl_getpriority pcntl_getqos_class pcntl_setcpuaffinity pcntl_setns pcntl_setpriority pcntl_setqos_class pcntl_signal pcntl_signal_dispatch pcntl_signal_get_handler pcntl_sigprocmask pcntl_sigtimedwait pcntl_sigwaitinfo pcntl_strerror pcntl_unshare pcntl_wait pcntl_waitid pcntl_waitpid pcntl_wexitstatus pcntl_wifcontinued pcntl_wifexited pcntl_wifsignaled pcntl_wifstopped pcntl_wstopsig pcntl_wtermsig php_sapi_name php_uname phpversion posix_setpgid posix_setsid print_r serialize unserialize unset var_dump zend_version Pointers 20 functions
buffer_new 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 81 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 PHP_URL_SCHEME PHP_URL_HOST PHP_URL_PORT PHP_URL_USER PHP_URL_PASS PHP_URL_PATH PHP_URL_QUERY PHP_URL_FRAGMENT ICONV_IMPL ICONV_MIME_DECODE_CONTINUE_ON_ERROR ICONV_MIME_DECODE_STRICT ICONV_VERSION STR_PAD_LEFT STR_PAD_RIGHT STR_PAD_BOTH PHP_ROUND_HALF_UP PHP_ROUND_HALF_DOWN PHP_ROUND_HALF_EVEN PHP_ROUND_HALF_ODD COUNT_NORMAL COUNT_RECURSIVE 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