php latest version code example
Example 1: php get version
echo PHP_VERSION;
Example 2: php versions and features
PHP Versions
PHP/FI - (1995)
Key Features - Form handling.
Description - Perl/CGI script (PHP 1.0) introduced by Rasmus Lerdorf. The Expansion is Personal Home Page / Form Interpreter and the ability to work with HTML.
PHP/FI2 - (1997)
Key Features - Data conversion,
Form data export,
HTML Embedding.
Description - With slight modifications in Form Interpreter(PHP 2.0) to handle form entries.
PHP 3 – (1998)
Key Features - PHP core is rewritten,
PHP parser is rewritten,
Zend Engine is incorporated.
Description - Language core was changed by Zeev Suraski and Andi Gutmans and PHP refers to PHP: Hypertext Preprocessor.
PHP 4 – (2000)
Key Features - Object-Oriented support,
External resource handling,
Security,
RegEx handling,
Enhanced run time execution,
Introduced Supergobals,
Web server abstraction layer,
Object overloading support
Output buffering support,
Improved resource handling.
Description - PHP version 4 powered by Zend Engine 1 was released for public usage.
PHP 4 also comes with the web server abstraction that enables PHP to run on Microsoft’s IIS, Apache 2, Zeus and more.
By 2008, PHP version 4 had evolved and reached 4.4.9. However, PHP version 4 is no more supported for security updates.
1.PHP 4 uses “Compile first, execute later” paradigm whereas other previous versions employed the “execute while interpreting” paradigm
2.PHP 4 hosted multi-threading feature; you can run the lengthy but non-critical functions independently, which further streamlines execution.
PHP 5 – (2004)
Aimed Features - Improved object model,
PDO Support,
Exception handling,
XML support.
Features of PHP 5. 1:
->Support for custom auto loading.
->Over 400 various bug fixes.
->Significant performance improvements
->Improved time zone support
Features of PHP 5.2:
->Improved memory manager
->Increased default memory limit
->New extensions with JSON, Zip
->Input filtering extension
->Upgraded bundle SQLite
Features of PHP 5.3:
->Support for namespaces
->Support for jump labels
->Dynamic access to static methods
->Support for Late Static Bindings
->A garbage collector for circular references
Features of PHP 5.4:
->Support for traits
->Tracking the upload progress of files
->Support for Binary number format
->Function array dereferencing
->Improved parse error messages
Features of PHP 5.5:
->empty() supports arbitrary expressions
->Generators
->password_hash()
->Introduced finally keyword
->array & string literal dereferencing
Features of PHP 5.6:
->Constant expressions
->SSL/TLS improvements
->Default character encoding
->pgsql async support
->Introduced phpdbg, an interactive debugger
->Operator overloading
->Gost-crypto hash algorithm
Description - PHP core was almost stabilized with this release.
Later 5.X releases have slight enhancement.
PHP version 5 scaled up to version 5.6. In December 2018, official support for PHP security ended but Debian continued to provide security support until 2020.
PHP 6 - PHP version 6 was supposed to feature native Unicode support, but that extension never succeeded.
In the month of March 2010, the project php 6.0 in its current form was officially abandoned and PHP’s version 5.4 was released with non-Unicode features like traits and closure binding.
This update left the developer community hoping for efficient Unicode integration.
So it was skipped and PHP 7 was released. You can get more information on this by going through the linked HN discussion.
PHP 7 – (2016)
Key Features - Improved performance (twice as that of 5.6),
Reduced memory usage,
The null coalescing operator (??),
Return and Scalar Type Declarations,
Anonymous Classes,
Zero cost asserts.
Features of PHP 7.1:
->Void functions
->Nullable Types
->Asynchronous Signal handling
->Class Constant visibility
->Symmetric Array Destructuring
Features of PHP 7.2:
->Abstract Method Overriding
->New Object Type
->Password hashing with Argon 2
Features of PHP 7.3:
->Trailing Comma
->Flexible Heredoc and Nowdoc Syntaxes
->PCRE2 Migration
->JSON_THROW_ON_ERROR
Features of PHP 7.4 (28 Nov 2019):
->Typed Properties 2.0
->Preloading
->Null Coalescing Assignment Operator
->Improve openssl_random_pseudo_bytes
->Weak References
->New custom object serialization mechanism
->Password Hash Registry
Example 3: latest php version
<?php
$json = file_get_contents('https://www.php.net/releases/?json');
$releases = [];
if ($json) $releases = json_decode($json, true);
/**
* Versions
Array
(
[0] => 7
[1] => 5
[2] => 4
[3] => 3
)
*/
$versions = array_keys($releases);
/** solution to: latest php version */
if (array_key_exists(max($versions), $releases)) {
echo $releases[max($versions)]['version']; // as of Aug 2020.. 7.4.9
}