PHP code example of xphp-lang / xphp

1. Go to this page and download the library: Download xphp-lang/xphp 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/ */

    

xphp-lang / xphp example snippets


// src/Collection.xphp
namespace App;

class Collection<T> {
    private array $items = [];

    public function add(T $item): void { $this->items[] = $item; }
    public function first(): ?T { return $this->items[0] ?? null; }
}

// src/Use.xphp
namespace App;

$users = new Collection::<User>();
$users->add(new User('Alice'));
$users->add(new User('Bob'));
echo $users->first()->name;