Created
January 14, 2016 09:22
-
-
Save schlessera/7d0719511a3b20c8a1a9 to your computer and use it in GitHub Desktop.
PHPFeature Example Usage Code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* PHPFeature example usage code | |
*/ | |
// Array of strings to define what features you need. | |
$features = array( 'namespaces', 'traits' ); | |
// Instantiate the PHPFeature library. | |
// When you don't provide a version number as the first argument, | |
// the version of the currently used PHP interpreter is fetched. | |
$php = new PHPFeature(); | |
// Check whether all of the features are supported. If not... | |
if ( ! $php->is_supported( $features ) ) { | |
// ... throw exception and let user know the minimum needed. | |
throw new RuntimeException( sprintf( | |
'Your PHP interpreter does not support some features needed to run this application. Please upgrade to version %1$s or newer.', | |
$php->get_minimum_required( $features ) | |
) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PHPFeature is a first draft of a PHP Feature Detection Library similar to what Modernizr does for the browser features. So, instead of checking for a specific PHP version number (which forces you to know which and compare which features were introduced by which versions), you can simply tell the library what features you need, and it will tell you with a simple boolean value whether these are supported or not.
Read more about it here: http://www.alainschlesser.com/php-feature/