PHP Documentation (English)

repository·master·Indexed 20 days ago

https://github.com/php/doc-en

English source files for the official PHP documentation used to generate the PHP manual at php.net/docs. This repository includes reference materials for PHP extensions, such as MongoDB and PSpell, and provides instructions for building the documentation locally using Docker and Make.

Tokens
2K
Snippets
7
Records
10
Agent score
70%

What's inside php-doc-en

  1. Conventions for per-extension entities

    master

    When creating or migrating textual entities related to specific extensions (replacing the old language-snippets.ent format), follow these naming and structural conventions:

    • Naming: Prefix all entity names with ext..
    • File Location: Place entities in doc-en/reference/$extension/entities.ent.
    • Organization: Keep entities sorted by name, with one empty line separating each entity.
    • Large Entities: If an entity is too large or complex for a shared file, create an individual file at doc-en/entities/name.$extension.$entname.xml. The content must be a well-balanced XML fragment. DTD entity names are allowed, but XML declarations are not.
    • Namespaces: Define XML namespaces in the root <entities> element only. Do not use namespaces within individual <entity> child elements.
  2. Build the PHP documentation locally with make and Docker

    master

    To build the documentation locally, ensure you have Docker installed. You can use the provided Makefile to automate the build process.

    By default, the build process will use doc-base or phd repositories if they are located in directories adjacent to this one.

    To view the results:

    1. Run make to build the documentation.
    2. Open the output/php-chunked-xhtml/ directory in your web browser.

    To build the web version of the documentation, use make php. The output will be located in output/php-web.

    # Rebuild the documentation
    make
    
    # Force rebuild of the Docker image
    make -B build
    
    # Build the web version
    make php
  3. Rename existing entities using temporary aliases

    master

    To rename existing entities to the new ext. prefixed format without breaking existing references immediately, you can create temporary aliases. This allows you to transition names gradually.

    It is recommended to place these aliases in doc-en/entities/entities-remove.ent to minimize redundant work in translation files, though they can also be placed in the extension's entity file.

    <entity name="old.name">&new.name;</entity>
  4. Structure of an extension entity file

    master

    An extension entity file should use the DocBook namespace and include the translate="yes" attribute on the root element. Entities should follow the ext.$extension.$entity-name naming pattern.

    <?xml version="1.0" encoding="utf-8"?>
    <!-- $Revision$ -->
    <!--
        See `manual.xml` for XML namespaces defaults.
        Keep the lines under 79 columns, to make the process of manual
        translation easier, and to avoid wrap-around in some other contexts.
    -->
    <entities xmlns       = "http://docbook.org/ns/docbook"
              xmlns:xlink = "http://www.w3.org/1999/xlink"
              translate   = "yes">
    
    <entity name="ext.$extention.$entity-name">
     <simpara>
      Text.
     </simpara>
    </entity>
    
    </entities>
  5. Access PHP documentation translations

    master

    The PHP documentation is translated into multiple languages. Each language has its own dedicated repository:

    • Brazilian Portuguese: doc-pt_br
    • Chinese (Simplified): doc-zh
    • English: doc-en (this repository)
    • French: doc-fr
    • German: doc-de
    • Italian: doc-it
    • Japanese: doc-ja
    • Polish: doc-pl
    • Romanian: doc-ro
    • Russian: doc-ru
    • Spanish: doc-es
    • Turkish: doc-tr
    • Ukrainian: doc-uk
  6. Use maxTimeMS within a command document

    master

    To restrict the amount of time a specific command can run on the server, include the maxTimeMS option directly within the document array passed to the MongoDB\Driver\Command constructor, rather than in the commandOptions parameter.

    <?php
    
    $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
    $command = new MongoDB\Driver\Command(
        array(
            "distinct" => "beer",
            "key" => "beer_name",
            "maxTimeMS" => 10,
        )
    );
    
    try {
        $cursor = $manager->executeCommand("beerdb", $command);
        $response = $cursor->toArray()[0];
    } catch(MongoDB\Driver\Exception\Exception $e) {
        echo $e->getMessage(), "\n";
        exit;
    }
    var_dump($response);
  7. Instantiate a new MongoDB\Driver\Command

    master

    The MongoDB\Driver\Command class is an immutable value object representing a database command. You create a command by passing a document (array or object) containing the command name and its parameters. This command object is then passed to MongoDB\Driver\Manager::executeCommand to be executed on the server.

    Important Distinction:

    • The document parameter should contain the complete command document as defined in the MongoDB manual (including command-specific options like maxTimeMS).
    • The commandOptions parameter is reserved strictly for driver-level options related to the execution and the resulting MongoDB\Driver\Cursor.
    <?php
    
    $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
    $command = new MongoDB\Driver\Command(array("buildinfo" => 1));
    
    try {
        $cursor = $manager->executeCommand("admin", $command);
        $response = $cursor->toArray()[0];
    } catch(MongoDB\Driver\Exception $e) {
        echo $e->getMessage(), "\n";
        exit;
    }
    var_dump($response);
  8. MongoDB\Driver\Command::__construct parameters

    master

    The constructor for MongoDB\Driver\Command accepts the following parameters:

    document (required)

    An array or object representing the complete command document that will be sent to the MongoDB server.

    commandOptions (optional)

    An array or null used to specify options related to the execution of the command and the resulting MongoDB\Driver\Cursor.

    Note: Do not use commandOptions to specify options described in the MongoDB manual (e.g., maxTimeMS). Use the document parameter for those. Only use commandOptions for the specific driver options listed below.

    // Signature:
    public final function __construct(
        array|object $document,
        array|null $commandOptions = null
    )
  9. Reference: commandOptions for MongoDB\Driver\Command

    master

    The commandOptions parameter in the MongoDB\Driver\Command constructor supports the following driver-specific option:

    OptionTypeDescription
    maxAwaitTimeMSintPositive integer denoting the time limit in milliseconds for the server to block a getMore operation if no data is available. This should only be used with commands returning a tailable cursor (e.g., Change Streams).
    // Example of using commandOptions
    $command = new MongoDB\Driver\Command($document, ['maxAwaitTimeMS' => 1000]);