PHP Source Code (php-src)

repository·master·Indexed 12 days ago

https://github.com/php/php-src

The core interpreter for the PHP scripting language. This documentation covers building PHP from source, developing core features, creating custom extensions, and configuring specific components like the Opcache JIT, embed SAPI, and bundled libraries such as bcmath, libsodium, and libmbfl.

Tokens
42.3K
Snippets
163
Records
214
Agent score
96%

What's inside PHP

  1. Overview of the bcmath library

    master
    The bcmath library provides arbitrary precision math routines. These routines are based on the calculations used in GNU bc and GNU dc. Unlike the GNU GMP library, bcmath uses a 'scale' model to represent the number of digits after the decimal point, ensuring exact precision for computations that require a specific number of decimal places.
  2. Overview of libavifinfo

    master

    The libavifinfo C snippet is used to partially parse AVIF payloads to extract metadata. It provides a lightweight alternative to the full libavif library for determining specific image properties.

    It can extract the following information from an AVIF image:

    • Width
    • Height
    • Bit depth
    • Channel count
  3. What is libmbfl?

    master

    libmbfl is a streamable multibyte character code filter and converter library. It is used within the PHP mbstring extension to handle various character encodings and conversions.

    Note that the version bundled with PHP is a fork of the original libmbfl repository and is maintained directly within the php-src repository to support PHP-specific requirements.

  4. What is timelib?

    master
    timelib is a timezone and date/time library used for calculating local time, converting between timezones, and parsing textual date/time descriptions. It serves as the underlying library for PHP's Date/Time extension and provides timezone support for MongoDB.
  5. What is the embed SAPI?

    master
    The embed SAPI (Server Application Programming Interface) is a lightweight entry point designed for calling into the Zend Engine from C or other languages with C bindings. It allows you to integrate the PHP interpreter directly into a host application.
  6. How the PHP interpreter executes opcodes

    master

    The interpreter reads and executes opcodes using a three-address code format, where each instruction typically has one result and up to two operands. Both results and operands are handled as zvals.

    • The complete list of opcodes is found in the generated Zend/zend_vm_opcodes.h.
    • The specific behavior of each opcode is defined in Zend/zend_vm_def.h.

    Execution Logic Example:

    • JMPZ: If the first operand is 'falsy', jump to the instruction at the second operand's address. Otherwise, fall through to the next instruction.
    • ECHO: Prints the first operand.
    • RETURN: Terminates the current function.
  7. Manage PHP extensions

    master

    PHP provides many essential bundled extensions. To add more functionality, you can use:

    • PIE (the PHP Installer for Extensions): Recommended for installing additional extensions.
    • PECL: The (now deprecated) PHP Extension Community Library.
    • PIE Extensions list: A searchable list of available extensions on Packagist.
  8. Configure a self-contained extension with config.m4

    master

    The config.m4 file uses M4 macros to define how the extension is built and configured. For a self-contained extension, you typically use PHP_ARG_ENABLE or PHP_ARG_WITH to handle configuration flags, and PHP_NEW_EXTENSION to define the extension name and its source files.

    To ensure the extension can be loaded as a shared module, pass $ext_shared as the third argument to PHP_NEW_EXTENSION.

    PHP_ARG_ENABLE([foobar],
      [whether to enable foobar],
      [AS_HELP_STRING([--enable-foobar],
        [Enable foobar])])
    
    if test "$PHP_FOOBAR" != "no"; then
      PHP_NEW_EXTENSION([foobar], [foo.c bar.c], [$ext_shared])
    fi
  9. What are PHP stub files?

    master

    Stub files are PHP files containing only declarations (constants, classes, methods, functions) with empty bodies. They are used to define the interface of PHP symbols without implementing their logic. Stub files conventionally use the .stub.php extension and are processed by build/gen_stub.php to generate C code (arginfo, function entries, class entries) or documentation.

    <?php
    /** @var string */
    const ANIMAL = "Elephant";
    
    class Atmosphere {
        public function calculateBar(): float {}
    }
    
    function fahrenheitToCelsius(float $fahrenheit): float {}
  10. Use attributes with zend_constant

    master

    The attributes field in a zend_constant is a HashTable that stores details about attributes applied to a constant.

    Important Limitation: Attributes can only be added to constants declared at compile time using the const keyword (e.g., const EXAMPLE = 123;). They cannot be applied to constants defined at runtime using the define() function (e.g., define('EXAMPLE', 123);).