Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHPFeature Example Usage Code.
<?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 )
) );
}
@schlessera

This comment has been minimized.

Copy link
Owner Author

commented Jan 14, 2016

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.