Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Use @template generics on resource-typed interface members instead of the generic resource type

Abierto
#170 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
52/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
php
Área
databases

Línea de trabajo

Locate DriverInterface, StatementInterface, and the concrete platform implementations; start by reading their existing resource docblocks and the related mago analyzer fixes. Apply the proposed generic contract consistently, then verify that concrete mysqli types no longer require downstream suppressions and that the static analyzers accept the implementations.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

enhancement next minor qa

Context

Found while working phpdb-mysql#60 (mago analyze fixes).

Problem

DriverInterface::createResult($resource), DriverInterface::createStatement($sqlOrResource), and StatementInterface::getResource() are documented with a generic resource docblock type, intended to stay valid across every supported RDBMS platform. Concrete per-platform implementations (e.g. phpdb-mysql) pass/return real objects (mysqli, mysqli_result, mysqli_stmt), not resource handles, since mysqli has been object-oriented since its introduction in PHP 5.0 and was never part of PHP's resource-to-object migration. Static analyzers (mago, phpstan, psalm) flag every concrete usage as a type mismatch against the generic resource docblock, requiring local suppressions in every downstream platform package.

Proposed direction

Use PHP docblock generics (@template) on the interfaces instead of a fixed resource type, so the interface stays a single, platform-agnostic contract, and each concrete implementation narrows the generic to its own real type via @implements:

/** @template TResource */
interface DriverInterface
{
    /** @param TResource $resource */
    public function createResult($resource): ResultInterface;
}
/** @implements DriverInterface<mysqli|mysqli_result|mysqli_stmt> */
final class Driver implements DriverInterface { /* ... */ }

This avoids introducing per-RDBMS interfaces (a platform still free to use literal resource handles, e.g. a hypothetical oci8 implementation, can declare DriverInterface<resource>), while letting static analyzers correctly understand each concrete implementation's real type without suppressions. Same pattern applies to StatementInterface::getResource() and DriverInterface::createStatement()'s $sqlOrResource parameter.

Lenguaje dominante
PHP
Estrellas
18
Forks
8
Merge medio
2 d 14 h
PR fusionados (30 d)
26

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de php-db/phpdb

Todos los issues de php-db/phpdb

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.