1. Go to this page and download the library: Download mckayb/phantasy-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/ */
mckayb / phantasy-types example snippets
use function Phantasy\Types\product;
$Point3D = product('Point3D', ['x', 'y', 'z']);
echo $Point3D; // 'Point3D'
$a = $Point3D(1, 2, 3);
echo $a; // 'Point3D(1, 2, 3)'
$Point3D->scale = function ($n) {
return $this->Point3D($n * $this->x, $n * $this->y, $n * $this->z);
};
/*
Could also do
$Point3D->scale = function ($n) use ($Point3D) {
return $Point3D($n * $this->x, $n * $this->y, $n * $this->z);
};
*/
$b = $a->scale(2);
echo $b; // 'Point3D(2, 4, 6)'