1. Go to this page and download the library: Download flashios09/php-union-types 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/ */
use \DateTime;
class Time extends DateTime
{
public static function today()
{
return new Time();
}
}
$today = Time::today();
$closure = function ($today) {
// `instanceOf` check is enabled by default
UnionTypes::assertFuncArg($today, [\DateTime::class, 'string']);
// some logic here
return $today;
};
// invocation
$closure($today);
$closure = function ($today) {
// disabled using the `instanceOf` option
UnionTypes::assertFuncArg($today, [\DateTime::class, 'string', ['instanceOf' => false]]);
// some logic here
return $today;
};
// invocation
$closure($today);
// config/bootstrap.php
define('UnionTypes.PATH_TO_APP', '/path/to/app/');
// using `$_SERVER`(isn't available in **php cli**)
$PATH_TO_APP = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR : '';
define('UnionTypes.PATH_TO_APP', $PATH_TO_APP);
// using `dirname(__FILE__)`, maybe you need to remove/add some parts, depending on the `__FILE__` location.
define('UnionTypes.PATH_TO_APP', dirname(__FILE__) . DIRECTORY_SEPARATOR;
// using the `PWD` key of the `getEnv()` array
define('UnionTypes.PATH_TO_APP', getEnv()['PWD'] . DIRECTORY_SEPARATOR;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.