[ create a new paste ] login | about

Link: http://codepad.org/MUNw3gn7    [ raw code | output | fork ]

PHP, pasted on Oct 18:
<?php
class LogFile
{
    public $formattedMatches;
    public $pathToLog;
    public $matchCount;
    public $matches;
    public function __construct()
    {
        $this->matches = new Matches();
    }
}

class Match
{
    public $owner;
    public $fileLocation;
    public $matchType;
}

class Matches extends ArrayObject
{
    public function offsetSet($name, $value)
    {
        if (!is_object($value) || ! $value instanceof Match)
        {
            throw new InvalidArgumentException(sprintf('Only objects of Match allowed.'));
        }
        parent::offsetSet($name, $value);
    }
}

$l = new LogFile();
$l->matches[] = new Match();

try
{
    $l->matches[] = 'test';
} catch(Exception $e) {
    echo 'There was an error: ', $e->getMessage();
}


Output:
1
There was an error: Only objects of Match allowed.


Create a new paste based on this one


Comments: