Questions Concepts
GitHub icon


PHP - Programming language

< >

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

Source code:
git clone
#9on PLDB 28Years Old 3mRepos

Try now: Riju · TIO · Replit

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...

Example from Riju:
<?php echo "Hello, world!\n";
Example from hello-world:
<?php echo 'Hello World';
<?php // Hello world in PHP echo 'Hello World!'; ?>
Example from Linguist:
#!/usr/bin/php <?php echo "PHP\n";
Example 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."
__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 Token Example
Access Modifiers
Switch Statements
While Loops
MultiLine Comments /* */
/* A comment
Print() Debugging echo
Line Comments //
// A comment
Increment and decrement operators
Variadic Functions
function sum(...$nums)
    return array_sum($nums);
echo sum(1, 2, 3); // 6
// 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
$name = "John"
Ternary operators
Here Document
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();
           'Undefined property via __get(): ' . $name .
           ' in ' . $trace[0]['file'] .
           ' on line ' . $trace[0]['line'],
       return null;
Strings '
"hello world"
Case Insensitive Identifiers X
Semantic Indentation X

View source

- Build the next great programming language · Search · Add Language · Features · Creators · Resources · About · Blog · Acknowledgements · Queries · Stats · Sponsor · Traffic · Traffic Today · Day 305 · · Logout