<?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();
}