public function __construct(array $prototype, array $data = []) { parent::__construct(count($prototype)); $this->prototype = $prototype; foreach ($data as $offset => $value) { $this->offsetSet($offset, $value); } }
/** * Constructor * * @param integer $size bloom-filter size (in bits) * @param array $hashes hash algorithms to use */ public function __construct($size, array $hashes) { if ($size <= 0) { throw new \UnexpectedValueException("Size cannot be negative or null"); } if (empty($hashes)) { throw new \UnexpectedValueException("You must provide at least one hash algorithm"); } $hashAlgos = hash_algos(); foreach ($hashes as $hash) { if (!in_array($hash, $hashAlgos)) { throw new \UnexpectedValueException("Hash algorithm {$hash} is not supported"); } } $this->hashes = $hashes; $this->size = $size; $this->count = 0; parent::__construct($size); }
public function __construct($size, $convert = false) { parent::__construct($size); $this->convert = (bool) $convert; }
/* negative init value */ try { $b = new SplFixedArray(-10); } catch (Exception $e) { var_dump($e->getMessage()); } /* resize and negative value */ $b = new SplFixedArray(); try { $b->setSize(-5); } catch (Exception $e) { var_dump($e->getMessage()); } /* calling __construct() twice */ $c = new SplFixedArray(0); var_dump($c->__construct()); /* fromArray() from empty array */ $d = new SplFixedArray(); $d->fromArray(array()); var_dump(count($a)); var_dump($a->count()); var_dump($a); /* foreach by ref */ $e = new SplFixedArray(10); $e[0] = 1; $e[1] = 5; $e[2] = 10; try { foreach ($e as $k => &$v) { var_dump($v); }