1. Go to this page and download the library: Download xchert/util library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xchert / util example snippets
use Xchert\Util\Value;
// Check if a value is normalized (only contains scalars or arrays of scalars)
Value::isNormalized('foo'); // true
Value::isNormalized(['foo', 'bar']); // true
Value::isNormalized(new \stdClass()); // false
// Check if a value is empty (considers whitespace as empty by default)
Value::isEmpty(''); // true
Value::isEmpty(' '); // true
Value::isEmpty(0); // false
Value::isEmpty(null); // true
// Normalize a value (converts it to a JSON-safe format: arrays and scalars)
$normalized = Value::normalize($someObject);
use Xchert\Util\Type;
// Get basic type of a value
Type::getType(123); // 'int'
Type::getType([]); // 'array'
// Check if a value matches a specific type (supports classes and interfaces)
Type::is(123, Type::INT); // true
Type::is('123', Type::NUMERIC); // false
Type::is($myObject, MyInterface::class); // true if $myObject implements MyInterface
// Validate a value (throws InvalidTypeException if validation fails)
Type::validate(123, Type::INT); // returns void
Type::validate('foo', Type::INT); // throws InvalidTypeException
// Check if a value is scalar
Type::isScalar(1.5); // true
Type::isScalar([]); // false
use Xchert\Util\Reflection;
$reflectionClass = new \ReflectionClass(MyClass::class);
// Get a property, including those from parent classes
$property = Reflection::getProperty($reflectionClass, 'myProperty');
// Get all properties, including those from parent classes
$properties = Reflection::getProperties($reflectionClass);
// Get a method, including those from parent classes
$method = Reflection::getMethod($reflectionClass, 'myMethod');
use Xchert\Util\ArrayUtil;
// Ensure a value is an array
ArrayUtil::ensure('foo'); // ['foo']
ArrayUtil::ensure(['foo']); // ['foo']
ArrayUtil::ensure(null); // []
// Convert any iterable to an array
$array = ArrayUtil::iteratorToArray($myGenerator);
// Deep clone an array (clones objects inside the array)
$clonedArray = ArrayUtil::clone($originalArray);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.