PHP code example of vehsamrak / phplist

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

    

vehsamrak / phplist example snippets




use Vehsamrak\ListCollection\TypedList;
use Vehsamrak\ListCollection\IntegerList;

$typedList = new TypedList(Foobar::class, [new Foobar(), new Foobar()]);

$foobar = new Foobar();
$typedList->add($foobar);
$typedList->remove($foobar);

$otherType = new OtherType();
$typedList->add($otherType); // will throw InvalidTypeException

$integerList = new IntegerList();
$integerList->add(1);
$integerList->add('not a number'); // will throw InvalidTypeException

// Examples could be found in `tests` directory

// More use cases can be found in Doctrine collections documentation:
// https://www.doctrine-project.org/projects/doctrine-collections/en/latest/index.html


use Vehsamrak\ListCollection\TypedList;

class CustomList extends TypedList
{
    public function __construct(array $elements = [])
    {
        parent::__construct(Custom::class, $elements);
    }
}