Ir al contenido

Missing cleanup pattern (ARCH7082)

Esta página aún no está disponible en tu idioma.

Key php.performance.dispose-pattern · Severity info · Category performance

If a class holds a closeable resource as a field but offers no cleanup method to release it, owned resources are never freed. Add a close method.

<?php
class Logger
{
private $fh;
public function __construct(string $path)
{
$this->fh = fopen($path, 'a');
}
}
<?php
class Logger
{
private $fh;
public function __construct(string $path)
{
$this->fh = fopen($path, 'a');
}
public function close(): void
{
fclose($this->fh);
}
}

Give classes that hold closeable fields an explicit close() method (or __destruct) that releases those resources.