for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
*
* This file is part of Phpfastcache.
* @license MIT License (MIT)
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
* @author Georges.L (Geolim4) <[email protected]>
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
declare(strict_types=1);
namespace Phpfastcache\Event;
use Phpfastcache\Exceptions\PhpfastcacheInvalidTypeException;
class EventReferenceParameter
{
protected mixed $parameter;
public function __construct(
mixed &$parameter,
protected bool $allowTypeChange = false
) {
$this->parameter = &$parameter;
}
public function getParameterValue(): mixed
return $this->parameter;
* @throws PhpfastcacheInvalidTypeException
public function setParameterValue(mixed $newValue): void
if (!$this->allowTypeChange) {
$currentType = \gettype($this->parameter);
$newType = \gettype($newValue);
if ($newType !== $currentType) {
throw new PhpfastcacheInvalidTypeException(
\sprintf('You tried to change the variable type from "%s" to "%s" which is not allowed.', $currentType, $newType)
);
$this->parameter = $newValue;
public function __invoke(): mixed
return $this->getParameterValue();