PLDB
Languages Features Calendar About Lists Add Language
GitHub icon

PHP

PHP

PHP, aka Personal Home Page, is a programming language created in 1995 by Rasmus Lerdorf.

PHP is a server-side scripting language designed primarily for web development but also used as a general-purpose programming language. Originally created by Rasmus Lerdorf in 1994, the PHP reference implementation is now produced by The PHP Development Team. PHP originally stood for Personal Home Page, but it now stands for the recursive acronym PHP: Hypertext Preprocessor. Read more on Wikipedia...

Try now: Riju Β· TIO Β· Replit

#8on PLDB 27Years Old 2.4mUsers

Example code from Riju:

<?php echo "Hello, world!\n";

Example code from hello-world:

<?php echo 'Hello World';

Example code from the Hello World Collection:

<?php // Hello world in PHP echo 'Hello World!'; ?>

Example code from Linguist:

#!/usr/bin/php <?php echo "PHP\n";

Example code from Wikipedia:

class Person { public $firstName; public $lastName; public function __construct(string $firstName, string $lastName = '') { // optional second argument $this->firstName = $firstName; $this->lastName = $lastName; } public function greet(): string { return 'Hello, my name is ' . $this->firstName . (($this->lastName != '') ? (' ' . $this->lastName) : '') . '.'; } public static function staticGreet(string $firstName, string $lastName) { return 'Hello, my name is ' . $firstName . ' ' . $lastName . '.'; } } $he = new Person('John', 'Smith'); $she = new Person('Sally', 'Davis'); $other = new Person('iAmine'); echo $he->greet(); // prints "Hello, my name is John Smith." echo '<br />'; echo $she->greet(); // prints "Hello, my name is Sally Davis." echo '<br />'; echo $other->greet(); // prints "Hello, my name is iAmine." echo '<br />'; echo Person::staticGreet('Jane', 'Doe'); // prints "Hello, my name is Jane Doe."

Keywords in PHP

__CLASS__ __DIR__ __FILE__ __FUNCTION__ __halt_compiler() __LINE__ __METHOD__ __NAMESPACE__ __TRAIT__ abstract and array() as break callable case catch class clone const continue declare default die() do echo else elseif empty() enddeclare endfor endforeach endif endswitch endwhile eval() exit() extends final finally for foreach function global goto if implements include include_once instanceof insteadof interface isset() list() namespace new or print private protected public require require_once return static switch throw trait try unset() use var while xor yield

Language features

Feature Supported Example Token
Conditionals βœ“
Inheritance βœ“
Access Modifiers βœ“
Switch Statements βœ“
Exceptions βœ“
Constants βœ“
Classes βœ“
While Loops βœ“
MultiLine Comments βœ“
/* A comment
*/
/* */
Print() Debugging βœ“ echo
Line Comments βœ“
// A comment
//
Increment and decrement operators βœ“
Functions βœ“
Variadic Functions βœ“
function sum(...$nums)
{
    return array_sum($nums);
}
echo sum(1, 2, 3); // 6
Traits βœ“
// The template
trait TSingleton
{
    private static $_instance = null; 
    private function __construct(){} // Must have private default constructor and be aware not to open it in the class
    public static function getInstance()
    {
        if (null === self::$_instance)
        {
            self::$_instance = new self();
        }
        return self::$_instance;
    }
}
class FrontController
{
    use TSingleton;
}
// Can also be used in already extended classes
class WebSite extends SomeClass
{
    use TSingleton;
}
Operator Overloading βœ“
Multiline Strings βœ“
$xml = <<
File Imports βœ“
Assignment βœ“
$name = "John"
Constructors βœ“
Comments βœ“
Magic Getters and Setters βœ“
    public function __set($name, $value)
   {
       echo "Setting '$name' to '$value'\n";
       $this->data[$name] = $value;
   }

   public function __get($name)
   {
       echo "Getting '$name'\n";
       if (array_key_exists($name, $this->data)) {
           return $this->data[$name];
       }

       $trace = debug_backtrace();
       trigger_error(
           'Undefined property via __get(): ' . $name .
           ' in ' . $trace[0]['file'] .
           ' on line ' . $trace[0]['line'],
           E_USER_NOTICE);
       return null;
   }
Strings βœ“
"hello world"
'
Booleans βœ“
Semantic Indentation Ο΄

Trending PHP repos on GitHub

repo stars description
Faker 21754 Faker is a PHP library that generates fake data for you
laravel 54813 A PHP framework for web artisans
framework 18676
monica 7726 Personal CRM. Remember everything about your friends and family.
mautic 3421 Mautic: Open Source Marketing Automation Software.
SecLists 19907 "SecLists is the security tester's companion. It's a collection of multiple types of lists used during security assessments collected in one place. List types include usernames passwords URLs sensitive data patterns fuzzing payloads web shells and many more."
web-frameworks 2932 Which is the fastest web framework?
monolog 15663 "Sends your logs to files sockets inboxes databases and various web services"
firefly-iii 2718 Firefly III: a personal finances manager
easyswoole 2336 "High performance Coroutine PHP Framework base on Swoole"
PrestaShop 3922 PrestaShop offers a fully scalable open source ecommerce solution.
akaunting 2097 Free and Online Accounting Software
phabricator 10942 Open software engineering platform and fun adventure game
yii2 13073 "Yii 2: The Fast Secure and Professional PHP Framework"
swoft 3829 πŸš€ PHP Microservice Full Coroutine Framework
elasticsearch-php 3510 Official PHP low-level client for Elasticsearch.
elementor 2505 "The most advanced frontend drag & drop page builder. Create high-end pixel perfect websites at record speeds. Any theme any page any design."
opencart 5040 A free shopping cart system. OpenCart is an open source PHP-based online e-commerce solution.
jwt-auth 8258 πŸ” JSON Web Token Authentication for Laravel & Lumen
cashier 1655
magento2 7806 "All Submissions you make to Magento Inc. (""Magento"") through GitHub are subject to the following terms and conditions: (1) You grant Magento a perpetual worldwide non-exclusive no charge royalty free irrevocable license under your applicable copyrights and patents to reproduce prepare derivative works of display publically perform subli…"
webshell 4829 This is a webshell open source project
twill 1507 "Twill is an open source CMS toolkit for Laravel that helps developers rapidly create a custom admin console that is intuitive powerful and flexible. Chat with us and others on Spectrum! https://spectrum.chat/twill"
hyperf 1186 "πŸš€ A coroutine framework that focuses on hyperspeed and flexibility specifically used for build microservices or middlewares."
composer 20839 Dependency Manager for PHP

Books about PHP on goodreads

title author year reviews ratings rating
Programming PHP Rasmus Lerdorf 2002 36 642 3.92
PHP and MySQL Web Development (Developer's Library) Luke Welling 2003 54 854 3.95
PHP & MySQL For Dummies Janet Valade 2002 11 186 3.53
Professional PHP Programming Sascha Schumann 1999 5 150 3.95
Advanced PHP Programming George Schlossnagle 2004 11 116 3.86

Article source

PLDB - Build the next great programming language. v5.0.0 - Acknowledgements Β· Email Β· GitHub