50 Fun Facts About PHP
Learn something new, then test yourself with the quiz.
Know these facts? Prove it.
Take the 50-question quizWhich programmer started PHP as a handful of small programs written to help maintain his own website?
Rasmus Lerdorf never meant to invent a language: he has said he simply kept adding the next logical step to his web tools.
PHP is now a recursive acronym for PHP: Hypertext Preprocessor, but which phrase did its letters originally abbreviate?
Personal Home Page Tools was the name of the first public release, which its author announced on a Usenet newsgroup in June 1995.
PHP's mascot was born when Vincent Pontier noticed the letters PHP resembled which animal seen from the side?
An elephant, nicknamed the elePHPant, has been PHP's mascot since 1998, and its plush-toy versions are now collectors' items, some of them extremely rare.
Which PHP content management system did Matt Mullenweg and Mike Little launch as a fork of b2/cafelog?
WordPress got its name from Christine Selleck Tremoulet, a friend of Mullenweg, and has grown from a blogging tool into software for shops, forums and whole websites.
Which social network created HipHop, a tool that turned its PHP code into C++ to ease the load on its servers?
Facebook retired HipHop in early 2013 in favour of HHVM, its own virtual machine, partly because the older tool was difficult to deploy.
Which symbol must come before every variable name in PHP, followed by a letter or an underscore?
A dollar sign opens every PHP variable, and the names are case-sensitive, so $age and $Age are two separate variables.
PHP error messages long called the :: operator Paamayim Nekudotayim, a name taken from which language?
Hebrew supplied the name when the team rewriting PHP's core for version 3 picked it, and the baffling term stayed in error messages until PHP 8.
Which bluntly named PHP function is an exact alias of exit, ending a script the moment it runs?
die does exactly what exit does: hand it a string and PHP prints that message just before the script stops.
In the LAMP stack, L is Linux, A is Apache and P can mean PHP; which database originally supplied the M?
MySQL took the M when a German magazine coined LAMP in 1998, although its community fork MariaDB now often fills the same slot.
PHP 7 added the three-way comparison operator <=>, which the PHP manual itself lists under what nickname?
Spaceship returns a negative number, zero or a positive number depending on which side is larger, exactly the answer a sorting callback has to give.
Which PHP output statement, unlike print, accepts several comma-separated arguments and returns no value?
echo is built into the language itself rather than being a true function, which is why it works without parentheses and cannot be called through a variable.
Which character joins two strings together in PHP, where JavaScript and Python would use a plus sign?
A dot glues strings together in PHP, and its partner .= appends text to the end of an existing variable.
A block of PHP code inside an HTML file opens with <?php; which two-character tag marks where it ends?
?> is best left off a file that holds only PHP, because stray spaces or blank lines after it would be sent to the browser by accident.
Which delimiters around a PHP string cause variable names inside it to be replaced by their values?
Double quotes make PHP expand variables and escape codes such as \n, while the same text in single quotes is output exactly as typed.
PHP jumped straight from version 5 to version 7 after the abandoned PHP 6 failed to deliver native support for what?
Unicode was to be stored internally as UTF-16, but the conversions hurt performance and too few developers understood the changes, so the effort was abandoned in 2010.
Which PHP comparison operator is true only when two values are equal and also of the same type?
=== is called the identical operator, and it exists because the looser == treats the number 5 and the text '5' as equal.
Which PHP loop works only on arrays and objects, visiting every element in turn without a counter variable?
A foreach loop hands over each value in turn, or each key and value together, and raises an error if it is pointed at anything other than an array or object.
What does the PHP manual call the ?? operator, which supplies a fallback when a variable has not been set?
Null coalescing arrived in PHP 7 to replace a wordy ternary check: $name ?? 'guest' yields the fallback without raising any notice or warning.
Which symbol, placed in front of a PHP expression, silences the warnings that expression would otherwise generate?
An at sign is PHP's error control operator, though since PHP 8 it can no longer silence the critical errors that stop a script.
PHP's execution operator, deprecated in version 8.5, runs text wrapped in which characters as a shell command?
Backticks behave exactly like a call to shell_exec(): the command's output comes back as a string instead of being printed.
Which PHP function returns the number of elements in an array and has sizeof as an alias?
count can also add up the elements of nested arrays in a single call when given the COUNT_RECURSIVE flag as a second argument.
Which kind of PHP array uses meaningful string keys such as 'email' in place of a numbered sequence?
Associative arrays are not a separate type: PHP draws no line between them and numbered lists, so one array can mix text keys and integer keys.
Since PHP 5.4, which pair of characters can create an array in place of the longer array() syntax?
Square brackets became a shorthand for array() in PHP 5.4, although the core developers had voted the same idea down in 2008, so [1, 2, 3] now builds a list directly.
Which PHP function splits a string into pieces at every separator, with an optional limit on how many come back?
explode turns a line such as 'a,b,c' into a three-element array, and its opposite number, implode, glues the pieces back together.
Which function for PHP arrays removes the last element and returns it, shortening the collection by one?
array_pop treats an array like a stack of plates, taking from the top; its mirror image array_shift removes the first element instead.
Which PHP function tells whether a value exists in a list, with an optional strict mode that also compares types?
in_array uses loose comparison unless its third argument is true, which is why careful code switches strict mode on to avoid surprise matches.
Which function joins two or more PHP arrays into one, renumbering any numeric keys from zero?
array_merge appends each list to the one before it, and when two inputs share a string key the later value overwrites the earlier one.
Which PHP function sorts an array by its keys in ascending order while keeping each key tied to its value?
ksort belongs to a family of one-letter variations: asort orders by value but keeps the keys, and krsort runs the key order in reverse.
Which PHP function builds an array from a start and an end value, so that passing 1 and 5 yields five numbers?
range also works on letters, so asking for 'a' to 'e' produces the first five letters of the alphabet, and a third argument sets the step size.
Which function runs a callback on every element of one or more PHP arrays and returns the results?
array_map returns a brand-new array, and given several inputs it feeds the callback one element from each of them at a time.
Which PHP keyword, written inside a function, binds a variable declared outside it into the function's local scope?
global is needed because a variable defined in the main script is not visible inside a PHP function by default, so it has to be imported by name.
Which PHP keyword makes a function's local variable keep its value between calls instead of starting afresh?
static variables are initialised only on the first call, so a function can use one to remember how many times it has already run.
Which built-in PHP array holds the values passed in a URL's query string, such as the 5 in ?id=5?
$_GET is filled from whatever follows the question mark in a page's address, and PHP decodes any percent-encoded characters automatically.
Which built-in PHP array keeps a visitor's data on the server from one page request to the next?
$_SESSION is filled once a session has started, and the browser normally carries only an ID cookie that PHP uses to find the stored data.
Which built-in PHP check confirms that a variable has been declared and holds a value, without raising a warning?
isset can take several variables in one call, and it returns true only if every single one of them is set.
What are PHP's anonymous functions also known as, a name shared with the internal class that implements them?
Closures can borrow variables from the surrounding code through the use keyword, and PHP turns each one into an object of the Closure class.
What does the PHP manual call the automatic conversion that lets the text '5' act as a number in arithmetic?
Type juggling happens whenever an operator needs a particular kind of value, so '5' + 3 quietly gives 8 instead of raising an error.
Which PHP keyword turns an ordinary function into a generator, handing back one value at a time and pausing in between?
yield lets a loop walk through a million values while using almost no memory, because each one is produced only when it is asked for.
Which PHP string syntax looks like a heredoc but leaves every variable name in its text unexpanded?
Nowdoc text is taken completely literally, which makes it ideal for embedding code samples or other large blocks that would otherwise need escaping.
PHP's password_hash() function, introduced in version 5.5, used which hashing algorithm as its original default?
Bcrypt was picked as a strong one-way algorithm, and password_hash() generates a fresh random salt for every password, so developers need not manage one.
Which PHP magic method, its name starting with two underscores, runs automatically each time a new object is created?
__construct replaced the old habit of naming the constructor after its class, a style that stopped working altogether in PHP 8.
Which PHP 5.4 feature lets unrelated classes reuse the same methods without inheriting from one another?
Traits were designed to ease the limits of single inheritance, and a class pulls one in with the use keyword inside its body.
Which PHP dependency manager, inspired by Node's npm and Ruby's Bundler, installs the packages listed in a JSON file?
Composer was first released in 2012 by Nils Adermann and Jordi Boggiano, and it fetches most of its libraries from the public Packagist repository.
Which PHP framework did Taylor Otwell create as a more advanced alternative to CodeIgniter?
Laravel was built because CodeIgniter lacked features such as built-in user authentication, and its second version added the Blade templating system.
Which engine at the heart of PHP is named by blending the first names of the two students who wrote it?
Zend began as a rewrite of PHP's core by two university students, Zeev Suraski and Andi Gutmans, whose first names it blends, and it has run PHP code since version 4 in 2000.
Early versions of PHP were released under the name PHP/FI; which two words did the letters FI stand for?
Forms Interpreter described the tool's main trick in the mid-1990s: reading the data sent from HTML forms and passing it on to databases.
PHP's creator grew up in Denmark and Canada, but in which Arctic territory was he born?
Greenland was his birthplace, in the town of Qeqertarsuaq, before the family moved to Denmark and then on to Canada in 1980.
Which extension bundled with PHP since 5.5 speeds up scripts by keeping precompiled bytecode in shared memory?
OPcache removes the need for PHP to load and parse a script on every single request, so repeat visits skip straight to running the stored code.
PHP 7 roughly doubled the language's speed thanks to a rewritten engine developed under which lowercase codename?
phpng stood for PHP next generation, and its more compact data structures also eased the later move to a just-in-time compiler.
Which PHP extension lets a developer step through a running script line by line and also profiles performance?
Xdebug also adds stack traces to PHP's notices, warnings and errors, highlighting the code path that led to the problem.