The PHP Interpreter

Overview

The PHP Interpreter

PHP is a popular general-purpose scripting language that is especially suited to web development. Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world. PHP is distributed under the PHP License v3.01.

Build status Build status Build Status Fuzzing Status

Documentation

The PHP manual is available at php.net/docs.

Installation

Prebuilt packages and binaries

Prebuilt packages and binaries can be used to get up and running fast with PHP.

For Windows, the PHP binaries can be obtained from windows.php.net. After extracting the archive the *.exe files are ready to use.

For other systems, see the installation chapter.

Building PHP source code

For Windows, see Build your own PHP on Windows.

For a minimal PHP build from Git, you will need autoconf, bison, and re2c. For a default build, you will additionally need libxml2 and libsqlite3.

On Ubuntu, you can install these using:

sudo apt install -y pkg-config build-essential autoconf bison re2c \
                    libxml2-dev libsqlite3-dev

On Fedora, you can install these using:

sudo dnf install re2c bison autoconf make libtool ccache libxml2-devel sqlite-devel

Generate configure:

./buildconf

Configure your build. --enable-debug is recommended for development, see ./configure --help for a full list of options.

# For development
./configure --enable-debug
# For production
./configure

Build PHP. To speed up the build, specify the maximum number of jobs using -j:

make -j4

The number of jobs should usually match the number of available cores, which can be determined using nproc.

Testing PHP source code

PHP ships with an extensive test suite, the command make test is used after successful compilation of the sources to run this test suite.

It is possible to run tests using multiple cores by setting -jN in TEST_PHP_ARGS:

make TEST_PHP_ARGS=-j4 test

Shall run make test with a maximum of 4 concurrent jobs: Generally the maximum number of jobs should not exceed the number of cores available.

The qa.php.net site provides more detailed info about testing and quality assurance.

Installing PHP built from source

After a successful build (and test), PHP may be installed with:

make install

Depending on your permissions and prefix, make install may need super user permissions.

PHP extensions

Extensions provide additional functionality on top of PHP. PHP consists of many essential bundled extensions. Additional extensions can be found in the PHP Extension Community Library - PECL.

Contributing

Contributions are most welcome by forking the GitHub repository and sending a pull request.

Discussions are done on GitHub, but depending on the topic can also be relayed to the official PHP developer mailing list [email protected].

New features require an RFC and must be accepted by the developers. See Request for comments - RFC and Voting on PHP features for more information on the process.

Bug fixes do not require an RFC but require a bug tracker ticket. Open a ticket at bugs.php.net and reference the bug id using #NNNNNN.

Fix #55371: get_magic_quotes_gpc() throws deprecation warning

After removing magic quotes, the get_magic_quotes_gpc function caused a
deprecated warning. get_magic_quotes_gpc can be used to detect the
magic_quotes behavior and therefore should not raise a warning at any time.
The patch removes this warning.

See Git workflow for more details on the pull request workflow.

Guidelines for contributors

See further documents in the repository for more information on how to contribute:

Credits

For the list of people who've put work into PHP, please see the PHP credits page.

Comments
  • Fix long messages to stdout/stderr getting truncated

    Fix long messages to stdout/stderr getting truncated

    The maximum zlog message length is 1024 including timestamp et cetera.

    With very long messages over 1024 characters, these get wrapped into multiple chunks correctly, but then the "WARNING: child blah said into blah" gets added and the zlog call truncates the messages using "..." at the end, resulting in a couple dozen bytes getting lost.

    This change calculates the length at which wrapping needs to occur correctly.

    To reproduce, log a long message to stderr, e.g. a bit of Shakespeare:

    file_put_contents('php://stderr', "If it were done when 'tis done, then 'twere well // It were done quickly. If the assassination // Could trammel up the consequence, and catch, // With his surcease, success; that but this blow // Might be the be-all and the end-all--here, // But here, upon this bank and shoal of time,-- // We'd jump the life to come. But in these cases // We still have judgement here; that we but teach // Bloody instructions, which being taught, return // To plague the inventor: this even-handed justice // Commends the ingredients of our poison'd chalice // To our own lips. He's here in double trust: // First, as I am his kinsman and his subject, // Strong both against the deed: then, as his host, // Who should against his murderer shut the door, // Not bear the knife myself. Besides, this Duncan // Hath borne his faculties so meek, hath been // So clear in his great office, that his virtues // Will plead like angels, trumpet-tongued, against // The deep damnation of his taking-off: // And pity, like a naked new-born babe, // Striding the blast, or heaven's cherubin, hors'd // Upon the sightless couriers of the air, // Shall blow the horrid deed in every eye, // That tears shall drown the wind.--I have no spur // To prick the sides of my intent, but only // Vaulting ambition, which o'erleaps itself, // And falls on the other. // Is this a dagger which I see before me, // The handle toward my hand? Come, let me clutch thee:-- // I have thee not, and yet I see thee still. // Art thou not, fatal vision, sensible // To feeling as to sight? or art thou but // A dagger of the mind, a false creation, // Proceeding from the heat-oppressed brain? // I see thee yet, in form as palpable // As this which now I draw. // Thou marshall'st me the way that I was going; // And such an instrument I was to use. // Mine eyes are made the fools o' the other senses, // Or else worth all the rest: I see thee still; // And on thy blade and dudgeon gouts of blood, // Which was not so before.--There's no such thing: // It is the bloody business which informs // Thus to mine eyes.--Now o'er the one half-world // Nature seems dead, and wicked dreams abuse // The curtain'd sleep; now witchcraft celebrates // Pale Hecate's offerings; and wither'd murder, // Alarum'd by his sentinel, the wolf, // Whose howl's his watch, thus with his stealthy pace, // With Tarquin's ravishing strides, towards his design // Moves like a ghost.--Thou sure and firm-set earth, // Hear not my steps, which way they walk, for fear // Thy very stones prate of my whereabout, // And take the present horror from the time, // Which now suits with it.--Whiles I threat, he lives; // Words to the heat of deeds too cold breath gives. // ");
    
    Bug Waiting on RM 
    opened by dzuelke 101
  • Fix #37676 : Add E_WARNING when using array-index on non valid container

    Fix #37676 : Add E_WARNING when using array-index on non valid container

    This bugfix attempts to resolve 37676. It will make sure that the container is either compiled, or if it's a return-variable make sure it's something that we know is error-able.

    Updated tests to account for the E_NOTICE that will go out with this fix.

    Other related bugs: 39915 72636

    RFC Waiting on Author 
    opened by bp1222 85
  • Implement stream_vt100_support user function

    Implement stream_vt100_support user function

    This is a followup of https://bugs.php.net/bug.php?id=72768

    TL;DR Console apps of newer Windows 10 versions support colors, but we need to manually set the ENABLE_VIRTUAL_TERMINAL_PROCESSING console flag.

    Here's my proposal of a new userland function: bool stream_vt100_support(resource stream[, bool enable])

    Where:

    • stream should be STDOUT orSTDERR
    • if enable missing: the function returns true if the specified stream supports colors
    • if enable is true: the function tries to enable color support for the stream (return true on success)
    • if enable is false: the function tries to disable color support for the stream (return true on success)

    To be done:

    • [X] currently the function accepts a string (eg php://stdout): it should instead accept a stream resource
    • [X] tests
    Feature 
    opened by mlocati 81
  • An attempt to implemnt

    An attempt to implemnt "preloading" ability.

    On startup, PHP may execute a script defined by opcache.preload configuration directive. All function and classes loaded by this script became permanent and available to all the following requests. For example, it's possible to preload almost whole Zend Framework, and save significant time on each request.

    This is an unfinished PoC yet.

    RFC 
    opened by dstogov 69
  • Added mixed argument type & return type

    Added mixed argument type & return type

    This is a proof of concept for built-in mixed type for parameter types and return types. The behavior of mixed type matches the behavior when no type is specified (thus being implicitly mixed). Primary motivation for having explicit mixed type is consistence and easier static analysis. In PHP 7.2, mixed types are unfortunately the only type that could not be type hinted upon (true, resource as well, but its future is unclear). I believe having mixed type would polish the code interface even more, thus having code with 100% explicit type hint coverage.


    Before:

    <?php
    function foo($arg) {
        return $arg;
    }
    
    

    Now:

    <?php
    function foo(mixed $arg): mixed {
        return $arg;
    }
    

    (Note that I barely know the PHP internals so this may be entirely wrong approach.)


    TODOs:

    • [x] disalow ?mixed at compile time?
    • [ ] add more tests?

    This probably needs an RFC, although mixed is already a reserved type. Since I don't have permission to create RFCs, a sponsor would be welcomed (anyone? 😇). Not sure whether it'd be too late for inclusion in 7.2 in case it'd be accepted (probably not yet since there's not even a beta yet).

    What do you think? 🚢

    RFC 
    opened by Majkl578 65
  • anon class objects

    anon class objects

    allow anonymous class objects

    <?php
    $var = new class {
        public $data;
    
        public function __construct($data) {
            $this->data = $data;
        }
    } ("Hello World");
    
    var_dump($var);
    
    interface IObject {
        public function iMethod();
    }
    
    function my_function(IObject $object) {
        return $object->iMethod();
    }
    
    var_dump(my_function(new class implements IObject {
        public function iMethod() {
            return __METHOD__;
        }
    }));
    ?>
    

    Thoughts ??

    opened by krakjoe 61
  • Apache / PHP segfaults (PHP 8.0 and 8.1, but also 7.4)

    Apache / PHP segfaults (PHP 8.0 and 8.1, but also 7.4)

    Description

    PHP 7.4.27 / 8.0.15 / 8.1.3 Apache 2.4.52 OpenBSD 7.0 / amd64

    If running any of the above PHP versions under Apache (as module), I noticed that every time when apache rotate it's logs it crashes. To be sure of this issue I set the log rotation at a fixed hour (not by size). In the last 3 days, each day at the exactly same hour apache crashed and did not crashed in the rest. Finally I did not loaded the opcache.so and it did not crashed on log rotation. After further investigation I noticed this:

    The problem is somwehere in opcache.so. All the above versions are affected. The PHP 7.3.33 works OK, it does not crash.

    How to reproduce the issue:

    1. load the opcache.so PHP extensions
    2. apachectl2 graceful OR kill -HUP 12345 (where 12345 is the process ID number)
    3. apache crashes

    If I do not load opcache.so it does not crashes.

    PHP Version

    8.0.15

    Operating System

    OpenBSD 7.0

    Bug Extension: opcache SAPI: apache2handler Status: Needs Triage 
    opened by unix-world 60
  • [PHP.NEXT] Add support for package private class, trait and interface

    [PHP.NEXT] Add support for package private class, trait and interface

    Consumes PR #931

    This PR allows this to be possible:

    namespace Foo 
    {
        private class Bar
        {
            // ...
        }
    }
    
    namespace Woo {
        class Fuzz extends Bar {}
    }
    

    To not be allowed as library developer of Foo may not have planned extension points in class Bar.

    RFC to be written yet...

    Implementation progress:

    • [x] Add lexical support for public classes, traits and interfaces
    • [x] Make sure public classes, traits and interfaces are supported correctly
    • [x] Add lexical support for private classes, traits and interfaces
    • [x] Implement compile time checks for private extension and implementation
    • [x] Implement run time check for private class instantiation
    • [x] Find a sponsor to review and help polish implementation (Nikita Popov)
    • [x] Implement ReflectionClass::isPublic() and ReflectionClass::isPrivate()
    • [x] Implement ReflectionClass::setAccessible()

    Add more tests coverage for:

    ReflectionClass:

    • [x] Add test for ReflectionClass::isPublic() with implicit value
    • [x] Add test for ReflectionClass::isPublic() with explicit value
    • [x] Add test for ReflectionClass::isPrivate() with explicit value
    • [x] Add test for ReflectionClass::setAccessible()

    Classes:

    • [x] Top level private class, top level instantiation
    • [x] Top level private class, top level class instantiation
    • [x] Top level private class, top level function instantiation
    • [x] Top level private class, top level closure instantiation
    • [x] Top level private class, top level clone instantiation
    • [x] Top level private class, top level class extension
    • [x] (FAIL) Top level private class, different namespace instantiation
    • [x] Top level private class, different namespace class instantiation
    • [x] Top level private class, different namespace function instantiation
    • [x] Top level private class, different namespace closure instantiation
    • [x] (FAIL) Top level private class, different namespace clone instantiation
    • [x] Top level private class, different namespace class extension
    • [x] Namespaced private class, top level instantiation
    • [x] Namespaced private class, top level class instantiation
    • [x] Namespaced private class, top level function instantiation
    • [x] Namespaced private class, top level closure instantiation
    • [x] (FAIL) Namespaced private class, top level clone instantiation
    • [x] Namespaced private class, top level class extension
    • [x] (FAIL) Namespaced private class, same namespace instantiation
    • [x] Namespaced private class, same namespace class instantiation
    • [x] Namespaced private class, same namespace function instantiation
    • [x] Namespaced private class, same namespace closure instantiation
    • [x] Namespaced private class, same namespace clone instantiation
    • [x] Namespaced private class, same namespace class extension
    • [x] (FAIL) Namespaced private class, different namespace instantiation
    • [x] Namespaced private class, different namespace class instantiation
    • [x] Namespaced private class, different namespace function instantiation
    • [x] Namespaced private class, different namespace closure instantiation
    • [x] (FAIL) Namespaced private class, different namespace clone instantiation
    • [x] Namespaced private class, different namespace class extension
    • [x] Any of the above test using autoloading

    Interfaces:

    • [x] Top level private interface, top level class implementation
    • [x] Top level private interface, different namespace class implementation
    • [x] Namespaced private interface, top level class implementation
    • [x] Namespaced private interface, same namespace class implementation
    • [x] Namespaced private interface, different namespace class implementation
    • [x] Any of the above test using autoloading

    Traits:

    • [x] Top level private trait, top level class usage
    • [x] Top level private trait, different namespace class usage
    • [x] Namespaced private trait, top level class usage
    • [x] Namespaced private trait, same namespace class usage
    • [x] Namespaced private trait, different namespace class usage
    • [x] Any of the above test using autoloading
    RFC Waiting on Author 
    opened by guilhermeblanco 57
  • Remove Zend signal handling

    Remove Zend signal handling

    Zend signal handling was added in PHP 5.4 to protect against signal handlers running at inopportune times and causing bugs. The details are in this RFC: https://wiki.php.net/rfc/zendsignals

    In short, the handlers for 7 signals of concern are saved and replaced with a generic handler which delegates to the specific handlers. Inside 'critical sections', however, the generic handler puts all information regarding a signal on a queue and just returns. At the end of the critical section, all pending signals on the queue are processed and the specific handlers are called.

    However, in PHP 7.1, the vm_interrupt flag was added which also protects against script execution timeouts, etc. occurring at wrong times. This eliminated most of the use cases of Zend signal handling. The one which has remained until now is accessing shared memory in OPCache. By eliminating the use of Zend signal handling there, there will be no need for Zend signal handling any more and a subsystem can be removed. This will make the codebase smaller and easier to understand.

    The funny thing about the whole idea of Zend signal handling is... it seems to duplicate what Unix kernels already do. Each process/thread in Unix already has a signal mask which can be used to block signals from being delivered at inopportune times. If a signal arrives when it is masked, the kernel will store it and only deliver it once it is unmasked. So rather than storing signals on a queue and unqueueing them later, we can just let the kernel to its job.

    Feature 
    opened by alexdowad 56
  • This PR adds support for CMS.

    This PR adds support for CMS.

    Hi everyone,

    This is my first PR for this project. It contains support for CMS, which is RFC 5652. The code borrows heavily from earlier work, because mostly speaking CMS is an incremental upgrade of PKCS#7. The notable changes are these:

    • PKCS7 struct to CMS_ContentInfo
    • Some internalizing of tests (e.g, they're shoved down to OpenSSL)
    • change in the field size for flags

    CMS is not present in all versions of OpenSSL. Notably Apple is doing something funky these days with LibreSSL. No idea how they are compiling PHP, but if a dependency is required, it is not yet in this PR.

    opened by elear 56
  • AIX/XCOFF support for fibers

    AIX/XCOFF support for fibers

    The fibers PR neglected to import the AIX-specific code from Boost's contexts library. This PR reinstates them and adds them to autoconf.

    May be required for non-_CALL_ELF==2 Linux, since that shares the AIX ABI (like, pretty much every non-LE enterprise distro, i.e. EL7).

    Category: Fibers 
    opened by NattyNarwhal 54
Owner
php.net
PHP is a popular general-purpose scripting language that is especially suited to web development
php.net
Analyzer of PHP code to search issues with deprecated functionality in newer interpreter versions.

PhpDeprecationDetector PhpDeprecationDetector - analyzer of PHP code to search usages of deprecated functionality in newer interpreter versions - depr

Sergey 298 Sep 21, 2022
Analyzer of PHP code to search issues with deprecated functionality in newer interpreter versions.

PhpDeprecationDetector PhpDeprecationDetector - analyzer of PHP code to search usages of deprecated functionality in newer interpreter versions - depr

Sergey 298 Sep 21, 2022
Sey is a powerful math interpreter with infinite-precision.

Sey, pronounce say, is a powerful math interpreter with infinite-precision.

Félix Dorn 13 Dec 5, 2021
The Current US Version of PHP-Nuke Evolution Xtreme v3.0.1b-beta often known as Nuke-Evolution Xtreme. This is a hardened version of PHP-Nuke and is secure and safe. We are currently porting Xtreme over to PHP 8.0.3

2021 Nightly Builds Repository PHP-Nuke Evolution Xtreme Developers TheGhost - Ernest Allen Buffington (Lead Developer) SeaBeast08 - Sebastian Scott B

Ernest Buffington 7 Aug 28, 2022
A sampling profiler for PHP written in PHP, which reads information about running PHP VM from outside of the process.

Reli Reli is a sampling profiler (or a VM state inspector) written in PHP. It can read information about running PHP script from outside of the proces

null 258 Sep 15, 2022
PHP Meminfo is a PHP extension that gives you insights on the PHP memory content

MEMINFO PHP Meminfo is a PHP extension that gives you insights on the PHP memory content. Its main goal is to help you understand memory leaks: by loo

Benoit Jacquemont 893 Sep 22, 2022
A sampling profiler for PHP written in PHP, which reads information about running PHP VM from outside of the process.

Reli Reli is a sampling profiler (or a VM state inspector) written in PHP. It can read information about running PHP script from outside of the proces

null 258 Sep 15, 2022
A multithreaded application server for PHP, written in PHP.

appserver.io, a PHP application server This is the main repository for the appserver.io project. What is appserver.io appserver.io is a multithreaded

appserver.io 948 Aug 31, 2022
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP

Lodash-PHP Lodash-PHP is a port of the Lodash JS library to PHP. It is a set of easy to use utility functions for everyday PHP projects. Lodash-PHP tr

Lodash PHP 466 Sep 15, 2022
A PHP 5.3+ and PHP 7.3 framework for OpenGraph Protocol

Opengraph Test with Atoum cd Opengraph/ curl -s https://getcomposer.org/installer | php php composer.phar install --dev ./vendor/atoum/atoum/bin/atoum

Axel Etcheverry 91 Feb 20, 2022
A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch screens with a resolution of 1024x600 connected to a Raspberry Pi.

EDStatusPanel A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch scr

marcus-s 20 Oct 15, 2021
🐘 A probe program for PHP environment (一款精美的 PHP 探針, 又名X探針、劉海探針)

Simplified Chinese | 简体中文 Traditional Chinese(Taiwan) | 正體中文(臺灣) Traditional Chinese(Hong Kong) | 正體中文(香港) Japanese | 日本語 ?? X Prober This is a probe

Km.Van 1.2k Sep 27, 2022
PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP language

php-text-analysis PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP l

null 458 Sep 12, 2022
PHP generics written in PHP

PHP generics written in PHP Require PHP >= 7.4 Composer (PSR-4 Autoload) Table of contents How it works Quick start Example Features Tests How it work

Anton Sukhachev 159 Sep 14, 2022
PHP exercises from my course at ETEC and some of my own play-around with PHP

etec-php-exercises PHP exercises from my course at ETEC and some of my own play-around with PHP Translations: Português (BR) Projects Project Descript

Luis Felipe Santos do Nascimento 6 May 3, 2022
GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.

GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.

Shivam Mathur 2.3k Sep 28, 2022
php-echarts is a php library for the echarts 5.0.

php-echarts 一款支持Apache EChart5.0+图表的php开发库 优先ThinkPHP5/6的开发及测试。 Apache EChart5.0已经最新发布,在视觉效果、动画效果和大数据展示方面已经远超之前的版本; 故不考虑EChart5.0之前版本的兼容问题;建议直接尝试5.0+

youyiio 5 Aug 15, 2022
Minimalist PHP frame for Core-Library, for Developing PHP application that gives you the full control of your application.

LazyPHP lightweight Pre-Made Frame for Core-library Install Run the below command in your terminal $ composer create-project ryzen/lazyphp my-first-pr

Ry-Zen 7 Aug 21, 2022
Zilliqa PHP is a typed PHP-7.1+ interface to Zilliqa JSON-RPC API.

Zilliqa PHP is a typed PHP-7.1+ interface to Zilliqa JSON-RPC API. Check out the latest API documentation. Add library in a composer.json file.

Patrick Falize 6 Oct 7, 2021