Top Related Projects
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.
The Symfony PHP framework
Dependency Manager for PHP
Yii 2: The Fast, Secure and Professional PHP Framework
CakePHP: The Rapid Development Framework for PHP - Official Repository
Open Source PHP Framework (originally from EllisLab)
Quick Overview
php/php-src is the official GitHub repository for the PHP programming language's source code. It contains the core implementation of PHP, including its interpreter, standard library, and various extensions. This repository is the primary development hub for PHP, where contributors collaborate to improve and maintain the language.
Pros
- Open-source and community-driven development
- Extensive documentation and active community support
- Regular updates and security patches
- Wide range of built-in functions and extensions
Cons
- Large codebase can be challenging for newcomers to navigate
- Some legacy code and design decisions may impact performance
- Inconsistent naming conventions in parts of the codebase
- Steep learning curve for contributing to core language features
Code Examples
- Hello World example:
<?php
echo "Hello, World!";
?>
This simple example demonstrates the basic syntax of PHP for outputting text.
- Array manipulation:
<?php
$fruits = ["apple", "banana", "orange"];
$fruits[] = "grape";
print_r($fruits);
?>
This code shows how to create and manipulate arrays in PHP.
- Database connection using PDO:
<?php
try {
$pdo = new PDO("mysql:host=localhost;dbname=testdb", "username", "password");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
This example demonstrates how to establish a database connection using PHP Data Objects (PDO).
Getting Started
To get started with PHP development:
- Install PHP on your system (e.g.,
sudo apt-get install php
on Ubuntu) - Create a new PHP file with a
.php
extension - Write your PHP code within
<?php ?>
tags - Run the PHP file using the command line:
php your_file.php
- For web development, set up a local web server like Apache or use PHP's built-in server:
php -S localhost:8000
To contribute to php/php-src:
- Fork the repository on GitHub
- Clone your fork:
git clone https://github.com/your-username/php-src.git
- Set up the development environment following the instructions in the
README.md
file - Make changes, commit, and push to your fork
- Create a pull request to the main php/php-src repository
Competitor Comparisons
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.
Pros of Laravel
- Easier to learn and use for rapid application development
- Built-in features like routing, ORM, and authentication
- Active community and extensive ecosystem of packages
Cons of Laravel
- Less flexibility for low-level system programming
- Higher overhead and potentially slower performance
- Dependency on specific PHP versions and extensions
Code Comparison
Laravel (routes/web.php):
Route::get('/', function () {
return view('welcome');
});
PHP (sapi/cli/php_cli.c):
int main(int argc, char *argv[])
{
sapi_startup(&cli_sapi_module);
return php_cli_startup(&cli_sapi_module);
}
Laravel focuses on high-level application development with expressive syntax, while PHP-src provides low-level control and core language implementation. Laravel abstracts many complexities, making it easier for developers to create web applications quickly. However, this abstraction comes at the cost of some performance overhead and reduced flexibility for system-level programming.
PHP-src offers more control over the language internals and is essential for developing PHP itself or creating extensions. It requires a deeper understanding of C programming and PHP's internal workings.
The choice between Laravel and PHP-src depends on the project requirements, with Laravel being more suitable for web application development and PHP-src for core language development and low-level system programming.
The Symfony PHP framework
Pros of Symfony
- Higher-level framework with more built-in features and abstractions
- Modular architecture allowing developers to use only needed components
- Extensive documentation and large community support
Cons of Symfony
- Steeper learning curve for beginners compared to vanilla PHP
- Potentially slower performance due to additional abstraction layers
- More opinionated, which may limit flexibility in some scenarios
Code Comparison
PHP (php-src):
<?php
$name = "World";
echo "Hello, $name!";
Symfony:
use Symfony\Component\HttpFoundation\Response;
public function index(): Response
{
return new Response('Hello, World!');
}
The PHP example shows raw PHP code, while the Symfony example demonstrates the use of Symfony's Response object and type hinting, showcasing the framework's more structured approach.
Summary
PHP-src is the core language implementation, providing low-level control and flexibility. Symfony, built on top of PHP, offers a comprehensive framework with pre-built components and conventions. While Symfony simplifies complex application development, it introduces additional complexity and potential performance overhead compared to raw PHP. The choice between them depends on project requirements, team expertise, and development priorities.
Dependency Manager for PHP
Pros of Composer
- Focused on dependency management, making it easier to handle PHP project dependencies
- More user-friendly for developers working on PHP applications
- Faster development cycles and easier project setup
Cons of Composer
- Limited scope compared to the core PHP language
- Requires PHP to be installed separately
- May introduce additional complexity for simple projects
Code Comparison
php-src (PHP core):
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec, ...) /* {{{ */
{
va_list va;
zend_result retval;
va_start(va, type_spec);
retval = zend_parse_va_args(num_args, type_spec, &va, 0);
va_end(va);
return retval;
}
Composer:
public function getPackages()
{
if (null === $this->packages) {
$this->loadPackages();
}
return $this->packages;
}
The php-src code is written in C and deals with low-level language implementation, while Composer's code is in PHP and focuses on package management functionality. php-src is more complex and requires deeper system-level knowledge, whereas Composer is more accessible for PHP developers working on application-level tasks.
Yii 2: The Fast, Secure and Professional PHP Framework
Pros of Yii2
- Higher-level framework, offering rapid application development
- Extensive built-in features like security, caching, and authentication
- Active community and comprehensive documentation
Cons of Yii2
- Steeper learning curve for beginners compared to vanilla PHP
- Less flexibility for low-level system programming
- Potential performance overhead due to abstraction layers
Code Comparison
PHP-src (raw PHP):
<?php
$name = "World";
echo "Hello, $name!";
?>
Yii2 (controller action):
public function actionHello($name = 'World')
{
return $this->render('hello', ['name' => $name]);
}
Summary
PHP-src is the core PHP language implementation, providing low-level control and serving as the foundation for PHP development. Yii2, built on top of PHP, is a high-level framework that offers rapid development capabilities and a rich set of features out of the box. While PHP-src gives developers more flexibility and direct access to language internals, Yii2 provides a structured approach to building web applications with pre-built components and conventions. The choice between them depends on the project requirements, developer expertise, and desired level of abstraction.
CakePHP: The Rapid Development Framework for PHP - Official Repository
Pros of CakePHP
- Higher-level framework with built-in conventions, leading to faster development
- Comprehensive set of tools and libraries for common web development tasks
- Active community and extensive documentation for easier learning and support
Cons of CakePHP
- Less flexibility compared to raw PHP for highly customized applications
- Additional overhead and potential performance impact due to framework abstraction
- Steeper learning curve for developers new to the framework's conventions
Code Comparison
PHP (php-src):
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
CakePHP:
// config/app.php
'Datasources' => [
'default' => [
'host' => 'localhost',
'username' => 'username',
'password' => 'password',
'database' => 'myDB',
]
]
The PHP example shows raw database connection code, while CakePHP uses a configuration file for database settings, abstracting the connection process and following convention over configuration principles.
Open Source PHP Framework (originally from EllisLab)
Pros of CodeIgniter4
- Easier to learn and use, with a gentler learning curve
- Built-in features for rapid application development (e.g., MVC architecture, database abstraction)
- Lightweight and faster performance for web applications
Cons of CodeIgniter4
- Less flexibility and customization options compared to raw PHP
- Smaller community and ecosystem compared to PHP core
- Limited to web application development, while PHP-src is a general-purpose language
Code Comparison
PHP-src (raw PHP):
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
CodeIgniter4:
<?php
$db = \Config\Database::connect();
if ($db->connID === false) {
die("Connection failed: " . $db->error());
}
The CodeIgniter4 example demonstrates its database abstraction layer, which simplifies database connections and operations compared to raw PHP. This abstraction provides a more streamlined approach for developers, especially in web application contexts. However, it also showcases the framework-specific nature of CodeIgniter4, which may limit its applicability in non-web scenarios compared to the more versatile PHP-src.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
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.
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
The PHP source code is located in the Git repository at github.com/php/php-src. Contributions are most welcome by forking the 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 internals@lists.php.net.
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 don't require an RFC. If the bug has a GitHub issue, reference it in
the commit message using GH-NNNNNN
. Use #NNNNNN
for tickets in the old
bugs.php.net bug tracker.
Fix GH-7815: php_uname doesn't recognise latest Windows versions
Fix #55371: get_magic_quotes_gpc() throws deprecation warning
See Git workflow for details on how pull requests are merged.
Guidelines for contributors
See further documents in the repository for more information on how to contribute:
- Contributing to PHP
- PHP coding standards
- Internal documentation
- Mailing list rules
- PHP release process
Credits
For the list of people who've put work into PHP, please see the PHP credits page.
Top Related Projects
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.
The Symfony PHP framework
Dependency Manager for PHP
Yii 2: The Fast, Secure and Professional PHP Framework
CakePHP: The Rapid Development Framework for PHP - Official Repository
Open Source PHP Framework (originally from EllisLab)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot