JPHP Documentation

repository·master·Indexed 23 days ago

https://github.com/jphp-group/jphp

JPHP is a PHP implementation that compiles source code into JVM bytecode. This documentation covers the core implementation and various extensions available via the JPPM package manager, including jphp-compress-ext for archive formats (Tar, Zip, Gzip, BZ2, Lz4), jphp-httpserver-ext for creating HTTP servers, jphp-graphic-ext for image manipulation, and other libraries for cryptography, JSON processing, HTML parsing (jsoup), email, and Markdown conversion.

Tokens
123.4K
Snippets
299
Records
1.2K
Agent score
80%

What's inside JPHP

  1. Overview of JPHP features and compatibility

    master

    JPHP is a PHP implementation that compiles PHP source code into JVM bytecode for execution on the Java Virtual Machine. It is designed to allow the use of Java libraries and classes directly within PHP code.

    Language Support

    • PHP 7.1+: Supports most features of PHP 7.1.
    • PHP 7.2: Supports all features except RFC: Parameter Type Widening.
    • PHP 7.3: Supports all features except RFC: Flexible Heredoc and Nowdoc Syntaxes.
    • PHP 7.4: Supports:
      • Typed Properties 2.0 (partially; references are not supported)
      • Weak References
      • Arrow Functions 2.0 (including multiple line syntax)
      • Throwing exceptions from __toString()
      • Null Coalescing Assignment Operator
      • numeric_literal_separator
      • Spread Operator in Array Expressions

    Key Capabilities

    • JIT Compilation: Provides performance improvements (approx. 2.5x faster than PHP 5.6).
    • Unicode: Full support for UTF-8 and UTF-16 (matching Java's string model).
    • Concurrency: Supports Java-style multithreading via php\lang\Thread.
    • GUI Development: Supports building desktop and Android applications using JavaFX or SWT.
    • Java Integration: Seamlessly use Java libraries and classes within your PHP scripts.
  2. Use the Regex class for regular expressions

    master

    The php\util\Regex class provides an immutable implementation of regular expression functionality. It allows for pattern matching, splitting strings, and performing replacements. Because the class is immutable, operations that modify the state (like region() or reset()) return a new instance or are handled via specific methods.

    Key capabilities include:

    • Static matching: Quick checks using match() or split() without manual instantiation.
    • Instance matching: Creating a Regex object to perform complex operations like finding all groups, replacing with callbacks, or managing search regions.
    • Escaping: Using quote() and quoteReplacement() to treat strings as literal patterns or replacement text.
  3. What is Flow and when to use it

    master
    The php\util\Flow class is a special immutable class designed for working with arrays and iterators using lazy operations. Flows are used to perform operations on collections while saving RAM memory by avoiding immediate evaluation of the entire set. Because the class is immutable, operations return new flow instances rather than modifying the existing one.
  4. What is the Flow class and when to use it

    master

    The php\util\Flow class is a specialized tool for working with arrays and iterators using a 'flow' abstraction. Flows enable lazy array and iterator operations, which helps save RAM memory by processing elements one by one rather than loading entire collections into memory.

    Note that Flow is an immutable class. Operations on a flow return a new flow instance rather than modifying the existing one.